I changed the value stored in /proc/sys/kernel/pid_max
. Do I need to reboot for this new value to take effect?

- 203

- 51
1 Answers
Should you have increased /proc/sys/kernel/pid_max
(by doing cat 100000 > /proc/sys/kernel/pid_max
for example), this value is effective right away, there is no need to reboot. I never tried to decrease it though(*).
You can test this the following way (that's somewhat ugly, not to be done on a production machine):
i=0 ; while [ $i -lt 10000] ; do (echo $i > /dev/null); ((i++)); done; ps ax | grep AnythingUnlikelyToBeUsedAlready
(echo $i > /dev/null)
is just there to create a new pid at each iteration. 10000 was convenient in my test case but you may adjust it. Here, it loops at run #3 as I previously set my pid_max
as described above:
shlublu:~$ i=0 ; while [ $i -lt 10000 ] ; do (echo $i > /dev/null); ((i++)); done; ps ax | grep AnuthingUnlikelyToBeUsedAlready
86880 pts/0 S+ 0:00 grep --color=auto AnuthingUnlikelyToBeUsedAlready
shlublu:~$ i=0 ; while [ $i -lt 10000 ] ; do (echo $i > /dev/null); ((i++)); done; ps ax | grep AnuthingUnlikelyToBeUsedAlready
96882 pts/0 S+ 0:00 grep --color=auto AnuthingUnlikelyToBeUsedAlready
shlublu:~$ i=0 ; while [ $i -lt 10000 ] ; do (echo $i > /dev/null); ((i++)); done; ps ax | grep AnuthingUnlikelyToBeUsedAlready
7246 pts/0 S+ 0:00 grep --color=auto AnuthingUnlikelyToBeUsedAlready
shlublu:~$ i=0 ; while [ $i -lt 10000 ] ; do (echo $i > /dev/null); ((i++)); done; ps ax | grep AnuthingUnlikelyToBeUsedAlready
17260 pts/0 S+ 0:00 grep --color=auto AnuthingUnlikelyToBeUsedAlready
shlublu:~$ i=0 ; while [ $i -lt 10000 ] ; do (echo $i > /dev/null); ((i++)); done; ps ax | grep AnuthingUnlikelyToBeUsedAlready
27262 pts/0 S+ 0:00 grep --color=auto AnuthingUnlikelyToBeUsedAlready
But should you restart after having done this you will see that /proc/sys/kernel/pid_max
will have been restored to its default value (32768 usually).
To make your setting persistant across restarts you have to edit /etc/sysctl.conf
and set kernel.pid_max
accordingly.
For example:
kernel.pid_max = 100000
Caveat: pid_max
has boundaries that depend on your system. The value you define should be within these limits.
(*) but @peterh did and it works obviously, see comments.

- 203
-
I tried to decrease, works like charm. From now, my PIDs will be reduced to 3 digits :-) Tyvm! – peterh Sep 27 '17 at 15:18
-
-
Btw, afaik the 32-bit pid support is an option in the kernels roughly 15 years ago, thus it is probably default in most distro kernels roughly a decade ago. Probably even 64-bit support pids wouldn't require too tremendous patches, but nobody needs them. – peterh Sep 27 '17 at 15:23
-
@peterh This is probably why the default is still 32768. I suppose that extending that value due to an actual need only happens with very very very busy machines. – Shlublu Sep 27 '17 at 15:25
-
@MarkPlotnick That's right, I should have said 'expect' instead. I'll edit that right away. – Shlublu Sep 27 '17 at 15:44
echo 999 >/proc/sys/kernel/pid_max
. You can increase or decrease as you wish. A change will affect only newly created processes. You can make the change permanent by inserting akernel.pid_max = 999
into your/etc/sysctl.conf
. Short pids are very handy, long pids look very professional (but they are not). The kernel wired-in max is 32-bit pids, so rougly 4billion. The default is 32766. – peterh Sep 27 '17 at 15:19