use Fcntl qw(:flock); use Symbol; fork(); # child and parent do the same operation my $fh = gensym; open $fh, ">/tmp/lock" or die "cannot open /tmp/lock: $!"; print "$$: I'm going to obtain the lock\n"; flock $fh, LOCK_EX; print "$$: I've got the lock\n"; sleep 30; close $fh;