Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

RE: Re: flock question

by takshaka (Friar)
on Jun 28, 2000 at 06:43 UTC ( [id://20121]=note: print w/replies, xml ) Need Help??


in reply to Re: flock question
in thread flock question

To work around this, you can lock a semaphore file instead of the actual file you are copying.
use strict; use File::Copy; use Fcntl ':flock'; # import LOCK_* constants my $status_file = "/tmp/flocktest"; my $semaphore = "/tmp/flocktest.sem"; open(SEM,">$semaphore") || die "Can't open file"; flock(SEM, LOCK_EX) || die "Can't lock file"; copy($status_file,"/tmp/foo"); unlink $semaphore; # only on unix close SEM;

Replies are listed 'Best First'.
RE: RE: Re: flock question
by Odud (Pilgrim) on Jun 28, 2000 at 12:13 UTC
    That's probably the simplest way around it - however when coding I tend to try to minimise the number of "things" that the script has to deal with. In this particular case a number of other files were being used but only one needed the lock and so it seemed logical to keep the lock with the file rather than create another object for the script to manipulate. Perhaps a good idea would be to come up with a generalised set of lock/unlock subroutines that I could use in all my scripts - I'll post it in snippets when I get it written.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-04-19 22:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found