Skip to content

Instantly share code, notes, and snippets.

@patrobinson
Last active December 29, 2015 03:49
Show Gist options
  • Save patrobinson/7610241 to your computer and use it in GitHub Desktop.
Save patrobinson/7610241 to your computer and use it in GitHub Desktop.
Mutex locking with bash
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