Bash: verify that process has stopped
- by pfac
I'm working on script meant to start/stop a set of services. For stopping, it has to terminate many processes which take a while and might hang.
The script needs to verify that the process has indeed terminated, and send an email if such does not happen after a given period.
This is what I have:
pkill -f "stuff"
for i in {1..30}; do
VERIFICATIONS=$i
if verification_command then
echo "It's gone"
break
fi
sleep 2
done
if [ $VERIFICATIONS -ge 30 ]; then
echo "failed to terminate"
# send mail
fi
Is there a better way to do this?