|Perl Monk, Perl Meditation|
Make a perl script self aware...by neuroball (Pilgrim)
|on Aug 01, 2003 at 17:57 UTC||Need Help??|
neuroball has asked for the
wisdom of the Perl Monks concerning the following question:
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)
Solution b) Do the same as in a) but don't save the PID, just some random piece of data.
Does some perlmonk have a better idea of check for existance of a script in memory that would work across platforms???