in reply to Re^3: how to exit if tool is already running
in thread how to exit if tool is already running
But they aren't always called, are they? The OS may crash. Something could kill it with SIGKILL. The application may exec.Furthermore, you have a problem if the program dies and doesn't get the chance to clean up the special file.Can be handled by either an exit handler
checking to see if the program is already running.So, now we're down to using external files, exit handlers, checking the process table, and using locks (which doesn't prevent a rm of the file).Write and/or exclusive locks handle this.
Even if it is not how you would do it (possibly for a full blown application), it may well fit the bill for this task.Or it may not. It sure ain't any simpler than
which doesn't require exit handlers, external files, does the right thing when the program exits unexpectedly, and doesn't have to check to process table.use Fcntl ':flock'; flock DATA, LOCK_EX|LOCK_UN or exit;
Now, I'm not claiming it isn't possible. I'm disagreeing with you that it's the easiest solution. Self-locking is easier than external locking.
|
|---|