Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: reliable lockfiles? (lock)

by tye (Sage)
on Jun 20, 2012 at 16:05 UTC ( #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? | Other CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2022-12-08 20:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?