##
open my $fh, "<", "whatever" or die $!;
flock $fh, LOCK_EX;
my $pid = open my $pip, "|-";
die "open(): $!" unless defined $pid;
if ($pid > 0) { close $pip }
else { flock($fh,LOCK_EX); print "got the lock"}
####
if ($pid > 0) { flock($fh,LOCK_EX); print "got the lock" }
else { sleep(20) }