I can't find any pattern when I look at the numbering of PIDs in process table (ps -a), as the PIDs are not subsequent numbers and sometimes there are large "gaps" between those numbers. Is it because there may be some processes that run for a short time and they reserve some PIDs? Is there some range, after which the numbering of processes resets?

I'm using Mac OS X but I guess that the answer should apply to UNIX in general.


Yes on both counts.

Many processes are short lived. They get a PID, run, finish, and the PID disappears from the process table.

Processes sometimes only live for a fraction of a second!

Often when programs start they run numerous commands as part of checking the system and initializing their environment.

The maximum PID number depends on the system and is sometimes configurable. Basically if you know you are going to have a huge number of processes, then you may need to increase the number, but on new operating systems I believe the maximum number is typically large enough for most any workload.

PIDs are entries in the process table, and the more you have the more memory the process table takes up.

Have a look at this related question: https://serverfault.com/questions/279178/what-is-the-range-of-a-pid-on-linux-and-solaris

Also note that related to this is the "maximum nr of processes per user" which is a measure to protect against a malicious user intentionally creating many processes to hog the whole process table.


It is also possible to configure some modern kernels to assign random PIDs to new processes for improved security. At least Linux and FreeBSD can do it with a sysctl setting, and OpenBSD does it always. In those cases you can say ever less about the numbering schemas.

  • Do you know what, if any, performance cost exists for this? Feb 26 '13 at 18:01
  • @Bruce: the first proposed patch had the worst case performance of O(infty) due the naive randomize. But I think they got something safe and usable. I didn't find anything very current on the topic... not that used I believe. :)
    – mike3996
    Feb 26 '13 at 18:22
  • 5
    Random PIDs sounds like security through obscurity to me.
    – Johan
    Feb 27 '13 at 7:43
  • That's what it is, mostly...
    – mike3996
    Feb 27 '13 at 8:08
  • Appart from individual initiatives, Linux used to propose it only through grsecurity patch, the Linux kernel team always refused to implement it (example here) and even grsecurity team finally dropped it in the late 2006. Jun 2 '15 at 21:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.