Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This shell script checks if process exists and removes pid file if not. I use this script with monit to be sure that process exist before killing it
#!/usr/bin/env bash
# the first argument should be a path to pid file
if [[ -f "$1" ]] ; then
if [ $(ps -p $(cat $1) | wc -l) -gt 1 ] ; then
# process exists - do nothing
#echo "OK"
exit 0
else
#echo "will do rm $1"
rm $1
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.