Finding the PIDs of all decendants

Boyd Roberts boyd at prl.dec.com
Fri May 17 20:42:34 AEST 1991


In article <1991May17.130543 at anusf.anu.edu.au>, mbl900 at anusf.anu.edu.au (Mathew BM LIM) writes:
> Has anyone got some C code which, given a PID, will (recursively) create
> an array of the PIDs of all it's decendants? 
> 
> If not, have you any ideas as to how to implement this?
> 

ps axl | sed 1d | awk '
BEGIN {
		p = 0
		parent[p++] = pid
}

{
		for (i = 0; i < p; i++)
		{
			if (parent[i] == $3)
			{
				parent[p++] = $2
				print "proc " $2 " parent " $3
				break
			}
		}
		next
}' pid=$1


Boyd Roberts			boyd at prl.dec.com

``When the going gets wierd, the weird turn pro...''



More information about the Comp.unix.programmer mailing list