Created
February 2, 2018 16:13
-
-
Save darxtrix/db2626307e954a47e282a85e33695c03 to your computer and use it in GitHub Desktop.
#linux
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
#!/bin/bash | |
#globals | |
export LOCKFILE="/var/tmp/trade_engine.lockfile" | |
export CMD="python print.py" | |
#release lock in case of trap signal | |
trap 'rm -f "$LOCKFILE"; exit $?' INT TERM | |
#acquire lock | |
flock -n $LOCKFILE $CMD | |
if [ $? -eq 0 ]; then | |
echo "Another process running of "$CMD | |
else | |
#clean up | |
rm -rf $LOCKFILE | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment