in reply to Abort if instance already running?
Don't know if using a flag(better: lock)-file is the best way to do it, but it should work for your purpose. Something along...
It is not race-condition proof, but 10-20 minutes in between runs is not a race condition, I guess.BEGIN { our $LOCKFILE = "/tmp/frogs.pid"; die "Another process is already running (see content of $LOCKFILE for + pid)...\n" if -e $LOCKFILE; open my $out, '>', $LOCKFILE or die "cannot open $LOCKFILE - $!"; print $out "$$\n"; close $out; # chmod 0600 ... if you like } warn "running... with PID: $$ ...\n"; sleep 10; END { unlink $LOCKFILE or die "cannot remove lock-file $LOCKFILE - $!"; }
|
|---|