Created
September 14, 2012 14:38
-
-
Save mschmitt/3722296 to your computer and use it in GitHub Desktop.
Script to test file locking
This file contains hidden or 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/perl -w | |
use strict; | |
use diagnostics; | |
use Fcntl qw(:flock); | |
my $lockfile = '/home/.test.lock'; | |
open my $lock_fh, ">$lockfile" or die "Can't open $lockfile: $!\n"; | |
if (flock($lock_fh,LOCK_EX|LOCK_NB)){ | |
print "Locked file: $lockfile\n"; | |
print "Press Enter to finish.\n"; | |
}else{ | |
close $lock_fh; | |
print "Could not acquire lock for: $lockfile\n"; | |
exit 1; | |
} | |
<>; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment