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

Re: Ensuring only one copy of a perl script is running at a time

by Skeeve (Vicar)
on Dec 19, 2006 at 16:28 UTC ( #590695=note: print w/ replies, xml ) Need Help??


in reply to Ensuring only one copy of a perl script is running at a time

If I can't use flock or a module, I usually go to create a "Semaphore" file, meaning, I define a filename and location and create a 0 byte file there. When the program starts, it tries to rename the file to some temporary name. If this succeeds, the program may run. If not, I retry or bail out.

the file has to be re-renamed when the program is done.

this algorithm assumes that file renaming is an atomic process, meaning that it can't be interrupted by the system and that a program, which renamed the file, really did so.


s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
+.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e


Comment on Re: Ensuring only one copy of a perl script is running at a time
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (8)
As of 2014-10-21 04:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (96 votes), past polls