Skip to content

Instantly share code, notes, and snippets.

@darxtrix
Created February 2, 2018 16:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save darxtrix/db2626307e954a47e282a85e33695c03 to your computer and use it in GitHub Desktop.
Save darxtrix/db2626307e954a47e282a85e33695c03 to your computer and use it in GitHub Desktop.
#linux
#!/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