1748137 Members
3642 Online
108758 Solutions
New Discussion юеВ

How OS picks the PID

 
SOLVED
Go to solution
skt_skt
Honored Contributor

How OS picks the PID

HP-UX 11.11/PA RISC
I happened to trace a Oracleprocess which is suppose to be terminating at a particular time( i was expecting them to be finish before 10.oo Hrs; see the extract o/p below). But i could see the same PID in the extract o/p more time running than expected. I am not sure if the same process was still running or a new one with same PID.

06/03/2009|07:45| 23367|oraclep500 |oracle | 0.00| 0.7| 4.5| 1.25| 0.25| 17704|
06/03/2009|07:46| 23367|oraclep500 |oracle | 0.00| 0.0| 0.7| 0.82| 0.44| 4988|
06/03/2009|09:16| 23367|oraclep500 |oracle | 0.00| 0.0| 0.0| 0.00| 0.00| 9592|
06/03/2009|09:33| 23367|oraclep500 |oracle | 0.00| 0.0| 0.0| 0.00| 0.00| 32|
06/03/2009|11:12| 23367|oraclep500 |oracle | 0.00| 0.0| 0.0| 0.00| 0.00| 3068|
6 REPLIES 6
Pete Randall
Outstanding Contributor
Solution

Re: How OS picks the PID

PID is sequentially assigned from 1 (the init process) up to PID_MAX (defined in limits.h) before they wrap around again. It is unlikely, unless you have an extremely busy system, that you would see a new process with the same PID.


Pete

Pete
Steven E. Protter
Exalted Contributor

Re: How OS picks the PID

Shalom,

There is a table out there and PID's are picked sequentially.

ITs very simple.

You might find a leak detector script I wrote useful in this hunt

http://www.hpux.ws/?p=8

It identifies processes by memory use and is very flexible.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Dennis Handly
Acclaimed Contributor

Re: How OS picks the PID

In order to provide the least surprise to users, free PIDs are kept around, instead of being reused right away.
Dennis Handly
Acclaimed Contributor

Re: How OS picks the PID

>ME: provide the least surprise to users

It seems in order to do this, PIDs can't be assigned sequentially, they would use a FIFO algorithm, which is initially sequential.
Dennis Handly
Acclaimed Contributor

Re: How OS picks the PID

Oops, I was wrong. PIDs are assigned sequentially but skipped if in use.
So on one ps(1) output, it is possible to see the same PID used for two processes.
V. Nyga
Honored Contributor

Re: How OS picks the PID

Well, with a 'ps -ef|grep ' you'll see when the process started, so it's simple to say if it's a new one.

Volkmar
*** Say 'Thanks' with Kudos ***