The flock Function
#!/usr/local/bin/perl
use Fcntl ":flock";
open (OUTFILE, ">>flockTest.txt") || warn $!;
print ("Requesting Exclusive lock\n");
flock(OUTFILE, LOCK_EX) || warn $!;
print ("This process now owns the Exclusive lock\n");
$in = <STDIN>;
flock(OUTFILE, LOCK_UN)|| warn $!;
close (OUTFILE);
unlink ("flockTest.lck");
Related examples in the same category