MacOS – Why are assigned PID numbers not sequential from 100

macosunix

If you look at a list of open processes, either in the Activity Monitor, or in Terminal with the TOP command, why are the assigned PID numbers not all used sequentially.

For example, is this because some processes with certain PID numbers have run and since ceased running, leaving a gap in sequential PID assigned numbers of existing running processes, or are their unlisted processes not visible in the Terminal tops command, or some other reason?

My understanding that after initial start up with PID numbers 0, 1 and a few more are assigned, PID numbers are then allocated from 100. As presented by:
AD: What's the maximum pid for Mac OS X?
And Wikipedia: Process Identifier.

Best Answer

Process numbers are assigned sequentially, starting with 1. The kernel is sort-of considered to be process #0, but it's not really a process, so this is a special case. It does not skip ahead to 100; that's something different. The gaps you see in the sequence are indeed due to processes that have finished. Most processes are sort-lived; they start, do some specific task, and then when the task is finished they exit.

As for that "100" figure, that has to do with what happens after 99,998 processes have started. That's the maximum PID, so at that point the system has "run out of numbers" and starts re-using them starting at 100. But this'll occur only after your computer has been running for quite a while, not during initial startup. It can take months or even years without a reboot before you run out of PIDs and restart from 100.