How Often do Unix process ids get recycled ?

How Often do Unix process ids get recycled ?

Post by Jeff Ime » Thu, 14 Mar 1996 04:00:00




> A system we have developed uses the popen function to pass report
> information to a Unix shell script. The script redirects the output to
> files / printers. Under some circumstances the process id of the script
> is used to uniquely identify files which would otherwise have the same
> name. Occasionally users have reported that during a large report run
> files have gone missing. Trace information indicates that the same
> process id was used twice during the run. To test this I wrote a small
> program :

> #include <stdio.h>

> main()
> {

>    FILE *p1 ;
>    int  i ;

>    for (i = 0 ; i < 500 ; i ++)
>    {
>       p1 = popen("spool", "w") ;
>       pclose(p1) ;
>    }

> }

> This is the spool script :

> #!/bin/sh
> echo $$ >> log

> I was surprised to see that in my log of 500 process ids, 64 had been
> used twice. I thought that process numbers were allocated in sequence
> until some maximum number was reached when they started again. Why are
> the numbers looping round so quickly ?

> I have tried this on a number of different platforms. Only the RS/6000
> seems to have a problem.

On the platforms I've used, the max PID available seems to be 29999.

YMMV.
--
Jeff Imes                         | Unix Sys V.4 System Administrator
NCR Corporation                   | Go Ohio State Buckeyes!
Dayton, OH  USA    (513) 445-6270 | #include <std.disclaimer>