#!/usr/bin/perl use strict; use warnings; use Fcntl qw(:flock); my $file = shift; open (F, "> $file") or die "Unable to open $file: $!"; my $lock_p = flock(F, LOCK_SH | LOCK_NB); if ($lock_p) { print "Got shared lock on semaphore file!"; my $wait = <>; # For testing - hold lock. flock(F, LOCK_UN) or warn "Problems unlocking $file: $!"; exit 0; } else { die "Ack! Didn't get a shared lock on $file: $!"; }