http://search.cpan.org/dist/Proc-Pidfile/Pidfile.pm

On Jan 25, 2012, at 2:06 PM, Paul Cupis wrote:

On 25/01/12 13:25, Henrik Aagaard Sørensen wrote:
What if the job suddenly takes more than 5 minutes to complete and
another job start, doing the same thing.

Couldn't that be a problem and can it be fixed?

Use Perls Fcntl module to ensure the program can only be running once -
if a second instance starts it will quit immediately and the next
scheduled run will pick up the remaining files.

Of course, if this happens to often you will take a long time to catch
up with the importing.

At the beginning of the script (after 'use File::Copy;') add:


use Fcntl qw(:flock);
unless (flock(DATA, LOCK_EX|LOCK_NB)) {
    exit;
    print "$0 is already running. Exiting.\n";
    exit(1);
}


and at the very end add:

__DATA__
This exists so flock() code above works.
DO NOT REMOVE THIS DATA SECTION.