Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.

share|improve this question
add comment

2 Answers 2

up vote 17 down vote accepted

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: http://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.

share|improve this answer
add comment

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.

share|improve this answer
    
Do you know what, if any, performance cost exists for this? –  Bruce Ediger 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. :) –  progo Feb 26 '13 at 18:22
4  
Random PIDs sounds like security through obscurity to me. –  Johan Feb 27 '13 at 7:43
    
That's what it is, mostly... –  progo Feb 27 '13 at 8:08
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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