Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Lock File

by eyepopslikeamosquito (Archbishop)
on Nov 02, 2010 at 20:58 UTC ( [id://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': $!";

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-04-20 00:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found