3

I have one server in a cluster that was experiencing a process table leak. Because the developer responsible for the code was unavailable for a few days I increased pid_max on the machine as follows:

echo 4194303 > /proc/sys/kernel/pid_max

This bought us time until the developer was able to fix his app and stop the leak.

However, I now would like to bring the server back inline with others in the cluster. My concern is that there are processes with pids in the 3 million range. If I reduce pid_max to its normal value, what will happen to pids already in the table? Does the system need to be restarted?

  • It is probably safe to reduce. But I am not sure a definitive answer could be given without knowing which kernel version. – kasperd Dec 01 '14 at 17:05
  • ps -efL | wc -l – c4f4t0r Dec 01 '14 at 17:11
  • @kasperd kernel version is 3.14.1 though I don't know if that helps much. – vastlysuperiorman Dec 01 '14 at 17:47
  • @c4f4t0r That tells me how many processes are running. I'm not sure how it relates to the question? Possibly you can clarify? Right now the number of processes is normal but pids are numbered ~3 million. Question is: If I reduce pid_max to 32768, what happens? – vastlysuperiorman Dec 01 '14 at 17:49

2 Answers2

1

Nothing will happen.

I wish I could say that the server would explode or at least catch fire, but nope...

As PIDs recycle, they'll fall into the defined range. You should really reboot and make the new setting persistent in sysctl.conf. But aside from padding/field issues, there's probably no harm to having a larger range of PIDs available.

ewwhite
  • 197,159
  • 92
  • 443
  • 809
  • Yeah, some part of me was hoping that there would be a massive show of fireworks followed by kernel meltdown (but how could software melt?). What I get from your answer is that the pid_max only matters when the system needs to generate a new pid, and has no effect on already existing processes. – vastlysuperiorman Dec 02 '14 at 15:10
1

To reduce pid_max you need to be sure, your system running processes are less the pid_max

ps -efL # L in ps list the threads, thread in linux has a pid as normal process

I used this in my linux workstation:

ps -efL | wc -l
307
sysctl -a | grep pid_max
kernel.pid_max = 32768
sysctl kernel.pid_max=2000
kernel.pid_max = 2000
sysctl -a | grep pid_max
kernel.pid_max = 2000
echo $((2000-307))
1693  ## there is pids available for new "procs|threads" ## after pid_max reduce
c4f4t0r
  • 5,301
  • 3
  • 31
  • 42
  • Been a long time since I looked at this question, but you bring up a good point. Reducing the pid_max below the number of running processes would prevent any new processes from starting. Good idea to check before reducing the number. – vastlysuperiorman Feb 25 '15 at 20:17