I am trying to use a lockfile so that the script can't be run again if it is
already running.  The below code works fine.  The problem is that if my
script runs with an argument for a config file with one person trying to run
it as "script.pl first.cfg" and the second person trys to run it as
"script.pl second.cfg" the second person can't run it.  How do I do a lock
in this case so that as long as the config files are different, it will
still run?  The below code is great since if the script is terminated, the
lock goes away.  If I actually create a file and put a lock on it and
terminate the script before deleting the lock file, I have to delete the
lock file manually, correct?

 

use Fcntl ':flock'; #import LOCK_* constants

INIT{

open *{0} or die "What!? $0;$!";

flock *{0}, LOCK_EX|LOCK_NB or die "$0 is already running somewhere!n";

}

 

Thanks

Steve

Reply via email to