Skip to content

Instantly share code, notes, and snippets.

@fornellas
Last active August 29, 2015 14:16
Show Gist options
  • Save fornellas/32190a8ec064c7134c5b to your computer and use it in GitHub Desktop.
Save fornellas/32190a8ec064c7134c5b to your computer and use it in GitHub Desktop.
Lock concurrent command execution
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