Created
August 30, 2013 11:35
-
-
Save toubib/6388993 to your computer and use it in GitHub Desktop.
SHELL: manage script PID
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### 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