Last active
August 29, 2015 14:16
-
-
Save fornellas/32190a8ec064c7134c5b to your computer and use it in GitHub Desktop.
Lock concurrent command execution
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
def procedure | |
puts 'Runnig...' | |
sleep 10 | |
end | |
File.open($0) do |io| | |
if io.flock(File::LOCK_EX|File::LOCK_NB) | |
procedure | |
else | |
puts 'Already running.' | |
exit 1 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment