1835251 Members
2310 Online
110078 Solutions
New Discussion

Next PID

 
Jim McKee
Occasional Contributor

Next PID

How does Unix determine the PID for a new process?
I have an application that uses the PID as part of a log file name. The application processes output files and runs many times during a day and each run is a new process. It appears that it comes up with the same PID, sometimes within a day or two, and end up with the output of two runs combined in one log file. I would have thought that with a maximum PID of 65k, it would take much longer than that to come around to the same PID.

Jim
But I'm feeling much better now........
1 REPLY 1
A. Clay Stephenson
Acclaimed Contributor

Re: Next PID

Hi Jim,

You are essentailly correct; PID's count up to 65535 and then recycle though low numbers (e.g. 1) are skipped and a test is done to see if the PID is in use. However, your filename creation may not be directly related to the PID value. It may simply test to see if such a file exists (e.g. the processes last temp file name) and use it if available. It is also possible that your are spawning many, many processes so that PID collision within a day or so is not unlikely.
If it ain't broke, I can fix that.