in reply to Re^3: self detecting script
in thread self detecting script

It's not so much that the filehand is left open when the exit event happens. Usually when the lockfiles are created the script simply writes its pid to the file and closes the filehandle to flush the file. Then when the script exists, the lockfile is deleted. However, if an unexpected exit happens, then the lockfile will still be around.

Replies are listed 'Best First'.
Re^5: self detecting script
by mpeters (Chaplain) on Sep 15, 2005 at 22:01 UTC
    Well, if you just rely on the prescence of the lock file then you open yourself up to a race condition. If you flock it, then it's prescence after the fact doesn't really matter does it? The next run of the script will be able to grab the same lock and write it's pid there if it needs to.

    -- More people are killed every year by pigs than by sharks, which shows you how good we are at evaluating risk. -- Bruce Schneier