Fellow Perlmonks,
I ask for your advise on how to make a script aware of itself (running as another process).
What I would like to archive is to make a script die when it knows it is already running in another process.
I thought up the following solutions, each having pitfalls though.
Solution a) Script 1 gets its own pid and writes it into a file. Script 2 checks for the file and pings the saved pid to see if the process is still running. If the pid is still existing Script 2 will die. (Script 1 will delete the file upon an error-free exit)
Pitfalls in a) WINDOWS (one of the environments the script has to run on) reuses pids.
Solution b) Do the same as in a) but don't save the PID, just some random piece of data.
Pitfalls in b) I wouldn't know if Script 1 exited in error and forgot to clean up after itself. I.e. Script 2 would always think Script 1 is running.
Does some perlmonk have a better idea of check for existance of a script in memory that would work across platforms???
thanks /neuroball/
In reply to Make a perl script self aware... by neuroball
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |