Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!swrinde!elroy.jpl.nasa.gov!decwrl!pa.dec.com!decprl!decprl!boyd From: boyd@prl.dec.com (Boyd Roberts) Newsgroups: comp.unix.programmer Subject: Re: Finding the PIDs of all decendants Message-ID: <1991May17.104234.26913@prl.dec.com> Date: 17 May 91 10:42:34 GMT References: <1991May17.130543@anusf.anu.edu.au> Sender: news@prl.dec.com (USENET News System) Reply-To: boyd@prl.dec.com (Boyd Roberts) Organization: Digital Equipment Corporation - Paris Research Laboratory Lines: 30 In article <1991May17.130543@anusf.anu.edu.au>, mbl900@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@prl.dec.com ``When the going gets wierd, the weird turn pro...''