in reply to Keeping track of children from previous runs of a script

Several options:

Replies are listed 'Best First'.
Re^2: Keeping track of children from previous runs of a script
by Illuminatus (Curate) on Mar 10, 2011 at 17:40 UTC
    I think salva's first option is the best way to go. If you are really paranoid about PID-wrap, you could put the executable name in the file along with the PID. Then, if you determine that the PID is active, you can use a variety of methods to determine the executable name and match that as well.

    fnord

      ajwood, note also that the methods described in my post are not mutually exclusive. Actually, it is quite common to combine the first two.
Re^2: Keeping track of children from previous runs of a script
by JavaFan (Canon) on Mar 10, 2011 at 18:33 UTC
    To avoid the problem of processes exiting before cleaning up, one could do the following: after the child has created its PID file, the child should lock the PID file. The lock will be gone as soon as the process exits - no matter what the reason of exiting is (well, I'm assuming a UNIX OS, I've no idea how other OSses work). To check whether a previous child is still running, open the PID files, and try to get a lock. If you can get a lock, the process is no longer running. Only if the file exists, and it's still locked, the process is still running.

    It also solves the problem of PID reuse.