programming-examples/perl/File/Wait for lock.pl

12 lines
314 B
Perl
Raw Normal View History

2019-11-15 12:59:38 +01:00
while (-e "flockTest.lck") {
print "waiting for lock\n"; sleep(1.0);
}
open (LOCK, ">flockTest.lck") || die "Lock error $!";
open (OUTFILE, ">>flockTest.txt") || warn $!;
print ("This process now owns the Exclusive lock\n");
$in = <STDIN>;
close (OUTFILE);
close (LOCK);
unlink ("flockTest.lck");