Skip to content

Instantly share code, notes, and snippets.

@mschmitt
Created September 14, 2012 14:38
Show Gist options
  • Save mschmitt/3722296 to your computer and use it in GitHub Desktop.
Save mschmitt/3722296 to your computer and use it in GitHub Desktop.
Script to test file locking
#!/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