On Linux, you can find the maximum PID value for your system with this:
$ cat /proc/sys/kernel/pid_max
This value can also be written using the same file, however the value can only be extended up to a theoretical maximum of 32768 for 32 bit systems or 4194304 for 64 bit:
$ echo 32768 > /proc/sys/kernel/pid_max
It seems to be normative practice on most 64 bit systems to set this value to the same value as found on 32 bit systems, but this is by convention rather than a requirement.
From man 5 proc
:
/proc/sys/kernel/pid_max
This file (new in Linux 2.5) specifies the value at which PIDs wrap around
(i.e., the value in this file is one greater than the maximum PID). The
default value for this file, 32768, results in the same range of PIDs as
on earlier kernels. On 32-bit platfroms, 32768 is the maximum value for
pid_max. On 64-bit systems, pid_max can be set to any value up to 2^22
(PID_MAX_LIMIT, approximately 4 million).
And no, you cannot change the PID of a running process. It gets assigned as a sequential number by the kernel at the time the process starts and that is it's identifier from that time on. The only thing you could do to get a new one is have your code fork a new process and terminate the old one.
In case you're referring Linux virtual consoles as TTYs, their number by default is 64 and this is defined in include/uapi/linux/vt.h
inside the Linux kernel source tree. The thing you're looking for is NR_CONSOLES
.
Best Answer
It seems to be a purely arbitrary choice. It could be anything, but somebody1 felt 4 million is enough. Use the source:
The history on git only seems to go back as far as 2005, and the value has been that at least as long.
1The manpage says that
/proc/sys/kernel/pid_max
was added in 2.5.34, and looking at the changelog, it looks like the somebody was Ingo Molnár:However, Ingo only addedDEFAULT_PID_MAX
.PID_MAX_LIMIT
was added by Linus Torvalds in 2.5.37:Turns out, I misread the changelog.
The changes are in the 2.5.37 patchset:
That's as far as my search skills get me.
Thanks to @hobbs, it seems Ingo is the somebody after all. The patch I quoted above was first sent by him. From the LKML post accompanying it:
There was a heated discussion about having higher limits, but it seems nothing came out of it in the end.