Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Determine if script is already running

by graff (Chancellor)
on Mar 03, 2003 at 01:01 UTC ( [id://239925]=note: print w/replies, xml ) Need Help??


in reply to Determine if script is already running

It would be helpful to know why you need to assure that only one instance of the script is running at any given time. The question would boil down to knowing what resource(s) (or what data) require the constraint: maybe it would be easier/safer to create a lock for the resource/data rather than for the process that uses it. For that matter, if it's an issue of ruling out concurrent access to a given chunk of data, maybe a DBMS (mysql or some such) could handle this job for you.

Also, since you talk about this being employed over multiple hosts in the workplace, you should clarify whether or not the "one copy at a time" applies globally to all hosts. That is, will it be okay to have two copies running at once, so long as those two are running on separate hosts? If not, then obviously your current approach won't handle the problem of locking out other hosts that might be competing for the resource/data. (update: your approach could be extended to handle this case by adding hostname to the pid file, and doing ssh or whatever when appropriate to check for the pid on some other host)

Apart from those concerns, and assuming that "one copy per host" is your intention, then you're present code seems good (if it works as-is on windows, which I don't know), and adding flock on the pid file probably won't improve on it much (er...) should be amended according to replies posted above.

  • Comment on Re: Determine if script is already running

Replies are listed 'Best First'.
Re: Re: Determine if script is already running
by Nitrox (Chaplain) on Mar 03, 2003 at 01:59 UTC
    The script in the current project is actually a long-running daemon that creates/deletes multiple HTML files which are part of a "health check" system for a Cisco SLB device.

    I should also have clarified in my original post, "one copy at a time" is on a per-host basis.

    -Nitrox

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2024-11-06 11:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    chatterbot is...






    Results (32 votes). Check out past polls.