Last active
December 29, 2015 03:49
-
-
Save patrobinson/7610241 to your computer and use it in GitHub Desktop.
Mutex locking with bash
This file contains 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
unset $LOCKED | |
LOCKFILE="/tmp/lockfile" | |
function waitlock | |
{ | |
while [ -d "$LOCKFILE" ]; do | |
sleep 10 | |
done | |
} | |
function lock | |
{ | |
echo "Attemping to get a lock on $LOCKFILE" | |
mkdir "$LOCKFILE" && LOCKED=1 | |
} | |
# Mutex locking bash style | |
while [ ! $LOCKED ]; do | |
waitlock() | |
lock() | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment