[Gllug] Getting PIDs

John Hearns john.hearns at cern.ch
Tue Aug 13 13:59:47 UTC 2002


On Tue, 2002-08-13 at 15:01, Stig Brautaset wrote:
> * Tethys <tet at accucard.com> spake thus:
> > 
> > >I was wondering if anyone knew of a nice way to get the PID
> > >of the parent of a process.
> 
> [snip]
> 
> > >Im writing startup scripts for a load of java apps that will spawn a
> > >load of children when run.
> > >
> > >What Im using at the moment is which is a bit of an ugly hack.
> > >
> > >pid=`ps auxwww |grep demo |grep -v initlog |grep -v bash | head -1 |awk
> > >'{print$2}'`
> > 
> > Rather than grepping the process table, it's far easier to just store
> > the PID of the process when it starts up:
> > 
> > 	#!/bin/sh
> > 
> > 	java -cp /foo/bar/demo StartJavaApp -Dinstance=1 &
> > 	echo $! > /var/run/demo1.pid
> > 
> > 	java -cp /foo/bar/demo StartJavaApp -Dinstance=2 &
> > 	echo $! > /var/run/demo2.pid
> > 
> > If you really do need to grep, then use a regexp rather than multiple
> > grep statements:
> > 
> > 	ps auxww | fgrep demo | egrep -v '(initlog|bash)'
> 
> Also have a look at pgrep.
> 

Bugger. I was going to come the smart-arse here, and
say that of course network managers would do this via an SNMP query.

But I can only get the PIDs, not the PPIDs via 
snmpwalk hostname public  25.4.2.1

Maybe I'm wrong though.




Oh, and for another smart-arse stupid way,
cat /proc/$pid/status and grep for PPID





-- 
Gllug mailing list  -  Gllug at linux.co.uk
http://list.ftech.net/mailman/listinfo/gllug




More information about the GLLUG mailing list