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.

Process IDs are strictly increasing, but if your system runs long enough and there is a lot of processes terminating and starting, you could at some point reach the limit of the underlying integral type (on my system it seems to be a signed int) where no larger pid would exists. Would this cause old unused ids (of processes that finished) to be recycled (i.e. handed out a second time)? What if somebody is waiting for that pid to terminate but didn't check in a looong time?

share|improve this question
    
This seems like a near duplicate of unix.stackexchange.com/questions/22425/… –  Bruce Ediger Dec 13 '11 at 4:47

1 Answer 1

up vote 6 down vote accepted

Process IDs are not strictly increasing on any UNIX-like operating system I know of. Your question is based on a false assumption.

The only requirements on process IDs are:

A process ID shall not be reused by the system until the process lifetime ends. In addition, if there exists a process group whose process group ID is equal to that process ID, the process ID shall not be reused by the system until the process group lifetime ends. A process that is not a system process shall not have a process ID of 1.

share|improve this answer
    
So that means, they are reused. But what if I wait for a child process to finish? By coincidence its process id could be reused before I get a chance to check it, right? –  bitmask Dec 13 '11 at 2:32
1  
No, that's impossible. The process is not finished until it reports its exit value to its parent. That is one of its jobs, and until it has done that, it is not finished. –  David Schwartz Dec 13 '11 at 2:38
    
@DavidSchwartz - not sure how readable this will be in a comment but - linux is pretty sequential. [adrian@iceweasel ~]$ a.out 24506 [adrian@iceweasel ~]$ a.out 24507 [adrian@iceweasel ~]$ a.out 24508 [adrian@iceweasel ~]$ a.out 24509 [adrian@iceweasel ~]$ cat pid.cc #include <stdio.h> #include <sys/types.h> #include <unistd.h> int main(int argc, char *argv[]) { printf("%d\n", getpid()); return 0; } –  Adrian Cornish Dec 13 '11 at 4:34
    
Most OSes are sequential until they wrap around. Some reserve certain ranges for processes of different types. A few have been random. –  David Schwartz Dec 13 '11 at 4:49
1  
Yes, they are not strictly increasing on an UNIX-like operating system I know of. If you know of one where they are strictly increasing, you haven't mentioned it yet. (Strictly increasing means that they never decrease.) I could imagine an OS with 64-bit PIDs that did that, but I don't know of any. –  David Schwartz Dec 13 '11 at 5:03

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.