Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Lock File

by eyepopslikeamosquito (Canon)
on Nov 02, 2010 at 20:58 UTC ( #869096=note: print w/ replies, xml ) Need Help??


in reply to Lock File

Yes, use flock. And strict, warnings and 3-argument open. Some sample locking code follows. Adjust according to your needs.

use strict; use warnings; use Fcntl ':flock'; # import LOCK_* constants open(my $fhlock, '>', $somelockfile) or die "Error: open '$somelockfil +e': $!"; # Note: process will block at this point until the lock is acquired. flock($fhlock, LOCK_EX) or die "Error: flock '$somelockfile': $!"; # Lock is now held until $fhlock is closed. # Note that even if this program crashes or is killed, $fhlock will # be closed by the OS and the lock released. # ... # Release the lock simply by closing the file handle. close $fhlock or die "Error: close '$somelockfile': $!";


Comment on Re: Lock File
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://869096]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (15)
As of 2014-07-14 16:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (268 votes), past polls