Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: How to do atomic file locking?

by Corion (Patriarch)
on Aug 25, 2015 at 17:53 UTC ( [id://1139904]=note: print w/replies, xml ) Need Help??


in reply to How to do atomic file locking?

The trick is to ignore the open call in your sequence of locking. Two or more processes can (on Unixish operating systems) successfully call open() on the same file, but only one call to flock() will succeed. That should be enough for your program to know whether it is the instance that should proceed or not.

Replies are listed 'Best First'.
Re^2: How to do atomic file locking?
by Acapulco (Novice) on Aug 25, 2015 at 20:44 UTC

    Thanks! I was not aware of this.

    So now my question is, if two files get to open the file (I'm working on Linux 2.6 kernel so I guess this can happen) but only one gets the lock.

    Which call will fail? The flock one? can I do "flock or die"?

    Again, thanks a lot. I couldn't find any references to this behavior.

      Nevermind. It seems that indeed I can do flock or die.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-03-29 10:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found