Operating System - Tru64 Unix
1829662 Members
10066 Online
109992 Solutions
New Discussion

Re: Allocation of PIDs on Tru64 5.1

 
Kevin Eady_1
Advisor

Allocation of PIDs on Tru64 5.1

Does anybody know how Tru64 allocates the next PID number ?

The reason that I am asking, is that I have noticed that the PIDs are not always greater than the last one used, as on most other O/S and I think this is causing me grief when I store these in an internal table.

Is there some sort of re-allocating of PIDs going on ?

Is there a kernel parameter to control this ?

Is this a feature/problem with 5.1 only ?

Any info would be appreciated.

Kevin
3 REPLIES 3
Greg Yates
Valued Contributor

Re: Allocation of PIDs on Tru64 5.1

Hi Kevin,

I did a quick look and found a couple of things.

PIDs do get reused but they (pid_entry's) should get tacked to the end of the free pid list when the process exits.

This certainly could produce out-of-order PIDs upon new process creation. I'm not aware of a tuneable to change this behavior.

Here are a couple of data structures you can look at on your system to see more of what's going on:

(dbx) p pid_data
struct {
pd_npids = 0x4000
pd_ntabs = 0x1
pd_nents = 0x4000
pd_ebits = 0xe
pd_pidtab = 0xfffffc0000ce05c0
pd_ptbases = (nil)
pd_freelock = 0x0
pd_freelist = 0xfffffc0000d31f80
pd_taillink = 0xfffffc0000d327d0
pd_usecount = 0x5a
pd_expwait = 0x0
pd_expbusy = (nil)
}
(dbx) p *pid_data.pd_freelist
struct {
pe_pid = 0x6a934
pe_gen = 0x1a
pe_ibn = '^N'
pe_flag = '^@'
pe_proc = (nil)
pe_link = 0xfffffc0000d32940
pe_lock = 0x0
}


Hope this helps.

Greg
Phillip Brown
Frequent Advisor

Re: Allocation of PIDs on Tru64 5.1

Yes, pid entries are reused. And there's an algorithm we use to ensure the same PIDs are not reused too quickly.

They're assigned distinct PIDs by adding 2pe_ibn for each new generation. (i.e. newpid = pid + pe_gen * 2 pe_ibn ).

We verify whether the entry in the pid table belongs to "our PID" by checking the pe_pid value (in pidtab array) once the entry is located.

The algorithm to locate your pidtab by PID is:

(kdbx) p PID & (pid_data.pd_nents -1)

That will give you the index into pidtab - p pidtab[index]. You should print it in hex so you can read the pe_ibn index. This will also give you the address to the proc structure where all things related may be found.

My pe_ibn is 0xc which would be 2^12, which equals 4096. So, we add that to our specific PID and compare that to the pe_pid to determine whether this slot belongs to this PID, or if the slot is being reused.

I am aware that certain code will scan the pidtab and if we find a slot that isn't in use (I believe we determine this by determining if the pd_proc field is null) then it's a candidate for re-use.

Regards,

Phil
Kevin Eady_1
Advisor

Re: Allocation of PIDs on Tru64 5.1

Thanks for the info.
I'm going to change the way that I process my internal table.
Just for the record, a log file that I was checking seemed to indicate that I had a re-used PID 35 seconds after the original.