On 6/22/11 Wed Jun 22, 2011 3:02 PM, "Steven Buehler" <st...@ibushost.com> scribbled:
> 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"; > > } I think you want to lock the config file ($ARGV[0]), not the program file ($0). -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/