Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Mechanism for ensuring only one instance of a Perl script can only run?

by talexb (Chancellor)
on Dec 04, 2022 at 16:14 UTC ( [id://11148548]=note: print w/replies, xml ) Need Help??


in reply to Mechanism for ensuring only one instance of a Perl script can only run?

I wrote a module for client (so I can't share the code) to take care of this, because I wanted to deal with the issue you described, as well as the issue where a previous run failed -- because some cleanup might need to be done.

I created an object based on the called script (I passed $0 in to the module) which then checked for a corresponding file in /var/run. If it existed, it meant that the script had been started previously. If the PID inside that file was still active, it meant the previous invocation was still running; if not, it meant that the script had crashed without 'unlocking' itself. And, of course, if the file didn't exist, I created it, using the PID of the currently running process.

This approach has worked well over the last three years.

Alex / talexb / Toronto

Thanks PJ. We owe you so much. Groklaw -- RIP -- 2003 to 2013.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2024-04-24 02:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found