Maximum PID in Linux

The maximum value of the PID in Linux is configurable. You can access it trough /proc/sys/kernel/pid_max file. 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. The value in this file can be set to any value up to 2^22 (PID_MAX_LIMIT, approximately 4 million).

From the programming perspective, you have to use pid_t type to work with process ID. You can even access its min/max values using integer traits. Here is an example of doing that using C++ and Boost on Linux 2.6.X running on x86_64 platform:

$ cat test.cpp 
#include <sys/types.h>
#include <iostream>
#include <boost/integer_traits.hpp>

using namespace std;

int main ()
{
    cout << "pid_t max = " << boost::integer_traits<pid_t>::const_max << endl;
}

$ ./test 
pid_t max = 2147483647

From the proc(5) man page:

/proc/sys/kernel/pid_max (since Linux 2.5.34)

This file specifies the value at which PIDs wrap around (i.e., the value in this file is one greater than the maximum PID). PIDs greater than this value are not allocated; thus, the value in this file also acts as a system-wide limit on the total number of processes and threads. The default value for this file, 32768, results in the same range of PIDs as on earlier kernels. On 32-bit platforms, 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).


It's 32768 by default, you can read the value on your system in /proc/sys/kernel/pid_max.

And you can set the value higher on 64-bit systems (up to 222 = 4,194,304) with:

echo 4194304 > /proc/sys/kernel/pid_max

Read more here:

http://www.cs.wisc.edu/condor/condorg/linux_scalability.html (via archive.org)

Tags:

Linux

C

Pid