Maximum PID in Linux
Solution 1
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)
Solution 2
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).
Solution 3
It seems that Ubuntu 20.04 has pushed the limit to the maximum (4194304):
% cat /proc/sys/kernel/pid_max
4194304
Comments
-
Alexander Stolz over 1 year
I am porting an application from Tru64 to Linux and it uses PID_MAX defined in limits.h. Linux doesn't have that define. How do I find PID_MAX in c without reading
/proc/sys/kernel/pid_max
by hand? Is there a library? -
Alexander Stolz over 12 yearsOk that was not what I wanted to do but I ended up reading the value from the file. I guess there is no other way.
-
derobert about 10 yearsThe Condor link in your answer went 404, unfortunately. I've replaced it with a link through archive.org, of course it'd be better if you know of a current version of the document.
-
Alexis Wilke about 5 yearsIs the limit shown in that
pid_max
file inclusive? Cangetpid()
return that very number or is the maximum that number minus one? (i.e. by default, can a process have PID 32768 or is the maximum 32767?) -
Sony Santos almost 5 yearsI'm glad that you included reference.
-
Maasoud Asadi over 3 yearsfor me it's 32768 (Ubuntu 20.04 WSL2)
-
Antti Haapala -- Слава Україні over 3 years@MaasoudAsadi interesting, I guess it might be because WSL2 might have another kernel...
-
Avio about 3 yearsNice, for
Ubuntu 20.04
it looks like/proc/sys/kernel/pid_max
is now set to4194304
... -
Zach Bloomquist over 2 yearsUbuntu 20.10 and 4194304 here.