[Gllug] Getting PIDs

Stig Brautaset stigbrau at start.no
Tue Aug 13 13:01:54 UTC 2002


* 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.

Stig

-- 
brautaset.org

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




More information about the GLLUG mailing list