in reply to Make a perl script self aware...
It is a common idiom to make note of a pid, record it somewhere, and have a program read it in, and check that the program is still running. You're quite unlikely to run into the problem of PID reusage (actually, I'm pretty sure all OSes reuse PIDs; the top number is almost always some power of two), but if you wanted to add another level of safety, it's only a little more work. If you're working with the /proc file system in a unix like environment, I know that some file or other contains the command line that was used to invoke a process. That's how the ps command knows this. Dig around and find where this info lives, and then use it to verify that a given PID is in fact for your script.
|
|---|