-
-
Save ahoward/734929 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
#! /usr/bin/env ruby | |
status = DATA.flock(File::LOCK_EX | File::LOCK_NB) | |
if status == 0 | |
puts "we have the lock..." | |
sleep | |
else | |
puts "another process has the lock..." | |
exit | |
end | |
__END__ | |
### this data section MUST be here for DATA.flock to function. | |
### the user locking the script MUST have write privledges to the script |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great idea! Just today I wrote a backup script and made use of this technique.