Skip to content

Instantly share code, notes, and snippets.

@toubib
Created August 30, 2013 11:35
Show Gist options
  • Save toubib/6388993 to your computer and use it in GitHub Desktop.
Save toubib/6388993 to your computer and use it in GitHub Desktop.
SHELL: manage script PID
### PID management
PID_FILE=/tmp/__SCRIPT_NAME__.pid
if [ -f $PID_FILE ];then
OLD_PID=$(<$PID_FILE);SEARCH_PID="x$(ps -p $OLD_PID -o pid h)"
test "$SEARCH_PID" != "x" && die "Already launched (pid $OLD_PID), exit"
fi
echo $$ > $PID_FILE
### END OF SCRIPT
#Delete pid file
rm -f $PID_FILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment