PID curiosity

New to SGIs? Need help getting things going? This is the forum for you!
Forum rules
Any posts concerning pirated software or offering to buy/sell/trade commercial software are subject to removal.
jpeg
Posts: 6
Joined: Sun Nov 05, 2006 12:17 am
Location: St Louis MO

PID curiosity

Unread postby jpeg » Mon Feb 26, 2007 6:50 pm

It doesn't look like Irix uses sequential ints for PIDs. Can anyone confirm this? Is it documented somewhere?

I'm also curious what the maximum value is. This single-user system has been up for 31 days and I haven't rolled over yet.

jpg@:/usr/people/jpg (1) $ ps
PID TTY TIME CMD
113865 ttyq8 0:00 ps
113887 ttyq8 0:00 sh
jpg@:/usr/people/jpg (2) $ ps
PID TTY TIME CMD
113884 ttyq8 0:00 ps
113887 ttyq8 0:00 sh
jpg@:/usr/people/jpg (3) $ ps
PID TTY TIME CMD
113875 ttyq8 0:00 ps
113887 ttyq8 0:00 sh
jpg@:/usr/people/jpg (4) $ ps
PID TTY TIME CMD
113876 ttyq8 0:00 ps
113887 ttyq8 0:00 sh
jpg@:/usr/people/jpg (5) $ ps
PID TTY TIME CMD
113867 ttyq8 0:00 ps
113887 ttyq8 0:00 sh
jpg@:/usr/people/jpg (6) $ ps
PID TTY TIME CMD
113887 ttyq8 0:00 sh
113894 ttyq8 0:00 ps
jpg@:/usr/people/jpg (7) $
--
jpg

User avatar
SupremeCmdr
Posts: 189
Joined: Wed Mar 01, 2006 1:38 am
Location: Sydney, Australia
Contact:

Unread postby SupremeCmdr » Tue Feb 27, 2007 12:38 am

Without source code for the IRIX kernel it is impossible to say what allocation scheme they use. I'd assume it is based on SysVr4 and since I cannot get a copy of the Magic Garden Explained http://www.amazon.com/Magic-Garden-Explained-Internals-Release/dp/0130981389 I'd look at Solaris for some ideas.

Apparently up to Solaris7 there was a limit on the MAXPID to 30,000, this is possibly fixed in later versions haven't looked yet. The relavent code is in pid_assign() in pid.c and from a quick look it appears to loop through a linked list of pid structures until it finds an unused one.

Interesting link to the NetBSD allocator which from memory uses a O(1) algorithm rather than the O(n) one used in Solaris.
http://kerneltrap.org/node/609

End brain dump :roll:
Apple Unibody MBP 2.66Ghz, 8Gb OSX 10.6
Apple MacMini 1.83Ghz, 1Gb OSX 10.5
Apple Power Mac Cube 450Mhz, 256Mb, OSX 10.3 Sweet!
Sun Ultra10 440Mhz 1Gb, SunOS 5.10

http://gothmog.homeunix.net/blog

User avatar
porter
Posts: 2917
Joined: Wed Nov 01, 2006 10:37 pm
Location: NZ

Unread postby porter » Tue Feb 27, 2007 1:05 am

SupremeCmdr wrote:MAXPID to 30,000,


Historically a pid was an int. Seeing as UNIX started on 16 bit machines and negatives meant errors, that make the true limit 32767.

Modern OS's now used "pid_t" which still can be an int, but on a 32 bit or 64 bit platform gives you (2^31)-1.

kramlq
Donor
Donor
Posts: 991
Joined: Tue Sep 20, 2005 5:10 pm
Location: IRL

Unread postby kramlq » Tue Feb 27, 2007 7:26 am

The Magic Garden (which was written by SGI engineers circa 1994) seems to suggest a similar algorithm was used in IRIX. But remember the IRIX kernel may have since been changed when adding thread support. And most highly scalable UNIX kernels will have increased PID size - perhaps a quick C program with sizeof(pid_t) will confirm this.

ALGORITHM
minpid = the number of system processes created at boot (usually 4)
mpid is a counter, which is initialised to minpid.
MAXPID is 30000, so pids range from 0...29999

Allocating a pid:
increment mpid (if it wraps MAXPID, reset it to minpid)
is pid 'mpid' currently in use*? if so, increment and try again.


* It searches a hashed linked list of PID structures (using the pid as a hash index) representing processes to find this out.

User avatar
regan_russell
Posts: 888
Joined: Tue Jul 18, 2006 9:32 pm
Location: Sydney, Australia
Contact:

Unread postby regan_russell » Tue Feb 27, 2007 11:27 am

kramlq wrote:The Magic Garden (which was written by SGI engineers circa 1994) seems to suggest a similar algorithm was used in IRIX.


Sorry, but no. The forward was written by a SGI engineer. The book is by Novell Engineers and is the first book of its nature to be fully approved by Novell inc ... Some things in the book are very not Irix like.

Regan
:Onyx2R: :Onyx2R: :0300: :0300: :0300: :O200: :Octane: :Octane: :O2: :O2: :Indigo2IMP: :Indy: :Indy: :Indy: :Indy: :Indy: :Indy: :Indy: :Indy:
:hpserv: J5600, 2 x SUN, 2 x Mac, 3 x Alpha, 2 x RS/6000

jpeg
Posts: 6
Joined: Sun Nov 05, 2006 12:17 am
Location: St Louis MO

Unread postby jpeg » Tue Feb 27, 2007 8:28 pm

eenteresting. Thanks, everyone.
--

jpg

LoWeN
Posts: 256
Joined: Thu Aug 28, 2003 11:45 am
Location: Belgium

Unread postby LoWeN » Thu Mar 01, 2007 6:04 am

Hello,

root 43714753 43043480 0 15:02:29 pts/11 0:00 grep ps

So the value can be very high (and this in 367 days).


@+

LoWeN
UX powered

User avatar
porter
Posts: 2917
Joined: Wed Nov 01, 2006 10:37 pm
Location: NZ

Unread postby porter » Thu Mar 01, 2007 8:12 am

LoWeN wrote:So the value can be very high


But not negative.

Code: Select all

     kill - send a signal to a process or a group of processes
                        ....
     If pid is negative but not -1, sig will be sent to all processes whose
     process group ID is equal to the absolute value of pid.
                        ....


Return to “Getting Started, Documentation, Tips & Tricks”

Who is online

Users browsing this forum: Google [Bot] and 2 guests