[NTLUG:Discuss] PID of program started from bash?
Kevin Brannen
kbrannen at pwhome.com
Wed Oct 13 21:37:54 CDT 2004
Jack Snodgrass wrote:
>I did man bash... I might have even tried it, but couldn't figure it
>out.... what's wrong with this test script?
>
>I first try and kill rhnsd so its not running.
>I then ps -aef and verify that it's not running.
>I then start it.
>I echo $!
>I ps -aef to see it's pid
>then I kill it...
>
>#!/bin/bash
>killall -TERM rhnsd
>echo "ps -aef | grep rhnsd "
>ps -aef | grep rhnsd | grep -v grep
>echo "starting..."
>/usr/sbin/rhnsd
>echo "$!"
>
>
$! won't work here because you didn't put "&" on the end of the command;
therefore no background process was started, and there was no PID to
store in $!. :-) Daemons which fork themselves off into the background
do not count as a background process to the shell.
Kevin
>echo "started..."
>echo "ps -aef | grep rhnsd"
>ps -aef | grep rhnsd | grep -v grep
>killall -TERM rhnsd
>
>
>
>as you can
>see..
>
>I get:
>./testit
>rhnsd: no process killed
>ps -aef | grep rhnsd
>starting...
>
>started...
>ps -aef | grep rhnsd
>root 12186 1 0 20:28 ? 00:00:00 /usr/sbin/rhnsd
>
>.... no $! is printed.....
>I tried
>echo $!
>and
>echo "$!"
>
>jack
>
>
More information about the Discuss
mailing list