I'm trying to kill a process, then verify if it's killed successfully. However I found that although it's killed, in the same script it still shows it's not killed. My script is like the following (running in a remote server by ssh first, that's why you see the remote parameter \$pid):
pid=`ps -ef | grep 'someprog' | grep sh | tr -s ' ' | cut -d ' ' -f2`
if [ ! -z "\$pid" ]; then
echo kill pid: \$pid
kill -9 \$pid
sleep 10
fi
pid1=`ps -ef | grep 'someprog' | grep sh | tr -s ' ' | cut -d ' ' -f2`
if [ ! -z "\$pid1" ]; then
echo \$pid1 is not killed yet
fi
Although I have "sleep 10", and I checked in another terminal this pid is gone, The test of pid1 is still true, and print the line "$pid1 is not killed yet". Can anyone help me so that I won't get into printing that line when it's already killed?