Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re: Lock File

by eyepopslikeamosquito (Chancellor)
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?

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (7)
As of 2015-11-27 08:59 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (722 votes), past polls