Created
September 15, 2015 17:46
-
-
Save manuq/a4b6790223906a9ae3c6 to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
# bash multi flock | |
# | |
# allow 3 instances of a bash function running at the same time | |
run_instance() { | |
( | |
flock -n 99 || return 1 | |
echo "starting instance $@..." | |
# do something here | |
sleep 10 | |
echo "done" | |
) 99>/tmp/test-${@}.lock | |
} | |
run_instance 1 || run_instance 2 || run_instance 3 || echo "BLOCKED!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment