in reply to Re: How can i check my script is already running?
in thread How can i check my script is already running?
I would create a pid file that tells you whether your program is running.There are two possible problems with that: it can generate false positives, and false negatives. If the pid file is removed for some reason, a next invocation can falsely determine no other invocation is running. OTOH, if an invocation dies unexpectedly, it may leave behind the pid file. By the time the program is invoked again, the pid may have been reused; the program would falsely determine there's another invocation, when there isn't. On top of that, to avoid race conditions, only one invocation should be able to modify the pid file at a time. But that means, in order to solve the problem (only one invocation at a time), you first have to solve the problem (only one invocation at a time accessing the pid file). You'd have to use file locks. But then you may as well use file locks in the first place.
I'd only use a pid file if there's a benefit in knowing the pid of the running instance.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: How can i check my script is already running?
by proceng (Scribe) on May 11, 2010 at 16:47 UTC | |
by JavaFan (Canon) on May 11, 2010 at 22:18 UTC |