[Gllug] Getting PIDs
Tethys
tet at accucard.com
Tue Aug 13 12:03:48 UTC 2002
>I was wondering if anyone knew of a nice way to get the PID
>of the parent of a process.
getpid()
Oh, you mean from a shell script...
ps -o ppid $pid
>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)'
Tet
--
Gllug mailing list - Gllug at linux.co.uk
http://list.ftech.net/mailman/listinfo/gllug
More information about the GLLUG
mailing list