I have a script that I need to put in some checking. It would read something like this but I need help with the exact notation:
#!/bin/bash
while true
if [ -z `ps -p 1234` ] #process is no longer reporting as up
echo "process 1234 has fell"
exit 1 # exit script
fi
sleep 1
#end of script
There is a lot of variation in the ps command.
Please post a sample command and output for a process which does exist and a process which does not exist. If you can find one on your system, please also post a sample for a zombie process.
The usual problem with processing the output from ps is disposing of the column headings.
#!/bin/bash
pid=${1:?Usage $(basename $0) pid}
while true
do
if ! kill -0 $pid 2>/dev/null; then #process is no longer reporting as up
echo "process $pid has fell"
exit 1 # exit script
fi
sleep 1
done