in reply to Re^2: How can i check my script is already running?
in thread How can i check my script is already running?
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.If the pid contained in the pid lock file is not in the process table, you should display a message asking if the process is running. If not, you can prompt the user to remove the file.
If the file does not exist (false negative), there is a logic error in your program (the pid lock file should be the first object created and the last destroyed).
You'd have to use file locks. But then you may as well use file locks in the first place.The point of using a predictable lock file (program_name.pid) in a predictable location (/var/run ?) is to handle all of the situations you describe. Data files used by the program may or may not be predictable. Directory locations may or may not be predictable (relative vs. absolute paths).
Using the conventions that have grown over the years (/var/run for pid lock files) work for a reason. YMMV
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^4: How can i check my script is already running?
by JavaFan (Canon) on May 11, 2010 at 22:18 UTC |