|P is for Practical
Re: Check for another running instance of the same programby dd-b (Monk)
|on May 13, 2013 at 22:34 UTC
You can safely automate the deletion of the semaphore file by writing the PID to it, and having later programs check if the PID exists as a running process; if not it can delete the file and proceed.
Consider your requirements carefully; for example, does it apply to one system, or all systems that can access a particular NFS mount, or all systems on a built-in list with IP connectivity, or what exactly. These lead to very different solutions. Do you want to consider expanding it to "no more than n" copies running at once, or is the simple one at a time good?