tru64-unix-managers (formerly alpha-osf-managers) (1994-2012)
 help / color / mirror / Atom feed
* SUMMARY 3:  C code to find all descendants of a given PID
@ 1998-12-09 11:42 lombardi emanuele
  0 siblings, 0 replies; only message in thread
From: lombardi emanuele @ 1998-12-09 11:42 UTC (permalink / raw)
  To: tru64-unix-managers


Dear friends (and expecially lucio)
I'm sorry I changed lucio's script to enhance (!!) it and as it always
happens now it works badly!

Please discard my previous mail and use the following script which is
named makeprocesstree . It it recursively called from itself so if you
change its name don't forget to edit itself !!

Sorry lucio and thanks to vincent lebrun which first discovered the
malfunction I added.


Grewetings from Italy,
Emanuele

-- 
 Emanuele Lombardi
 mail:  AMB-GEM-CLIM ENEA Casaccia
        I-00060 S.M. di Galeria (RM)  ITALY
 mailto:lele@mantegna.casaccia.enea.it
 tel	+39 6 30483366 fax	+39 6 30483591

     This transmission was made possible by 100% recycled electrons.





#!/bin/csh
setenv CMD_ENV bsd   #for /usr/bin/echo -n to work
#
# print tree of PIDs under a given pid
#
# may be called recursively, if not use level 0 (from command line)
  if ($#argv != 2) then
     set level = 0
  else
     set level = $2
  endif
#
# does wished process exist ?
  set pid = `ps -A -o user,pid,ppid,ucomm | awk -v mypid=$1 -v thispid=$$ '$2==mypid && $2!=thispid {print $1,$4}'`
  if ($#pid == 0) then
    echo "no such process"
    exit
  endif
#
# it does exist, print a number of tabs equal to the level minus one
  if ($level != 0) then
     set i = 0
loop:
     @ i++
     /usr/bin/echo -n "\t"
     if ($i != $level) goto loop
  endif
#
# echo my name and pid
  echo $1 $pid
#
# get any sons (ignore the instances of this program)
  set sons = `ps -A -o user,pid,ppid,ucomm | awk -v mypid=$1 '$3==mypid && $4!="makeprocesstree" {print $2}'`
#
# no sons
  if ($#sons == 0) then
#    echo "no sons"
     exit
  endif
#
# increment level by one
  @ nlevel = $level + 1
# and call recursively for each son
  foreach i ($sons)
     makeprocesstree $i $nlevel
  end

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1998-12-09 11:42 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1998-12-09 11:42 SUMMARY 3: C code to find all descendants of a given PID lombardi emanuele

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox