Wait for lock : LOCK « File « Perl






Wait for lock

    

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");

   
    
    
    
  








Related examples in the same category