Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: reliable lockfiles? (lock)

by tye (Sage)
on Jun 20, 2012 at 16:05 UTC ( [id://977389]=note: print w/replies, xml ) Need Help??


in reply to reliable lockfiles?

Create the lock file if it doesn't exist. Then lock it, exclusively (such as via flock). No matter how your process dies, the lock will be released when the process is no longer running. Trying to lock the lock file will fail only if another process is already running. You don't even have to worry about a PID getting re-used. Don't have code that deletes the lock file. For monitoring convenience, after locking of the file succeeds, write your PID to the file.

This also has the major advantage of preventing a classic race condition where you end up with two instances running.

- tye        

Log In?
Username:
Password:

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

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

    No recent polls found