<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><a href="http://search.cpan.org/dist/Proc-Pidfile/Pidfile.pm">http://search.cpan.org/dist/Proc-Pidfile/Pidfile.pm</a><div><br><div><div>On Jan 25, 2012, at 2:06 PM, Paul Cupis wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>On 25/01/12 13:25, Henrik Aagaard Sørensen wrote:<br><blockquote type="cite">What if the job suddenly takes more than 5 minutes to complete and<br></blockquote><blockquote type="cite">another job start, doing the same thing.<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">Couldn't that be a problem and can it be fixed?<br></blockquote><br>Use Perls Fcntl module to ensure the program can only be running once - <br>if a second instance starts it will quit immediately and the next <br>scheduled run will pick up the remaining files.<br><br>Of course, if this happens to often you will take a long time to catch <br>up with the importing.<br><br>At the beginning of the script (after 'use File::Copy;') add:<br><br><br>use Fcntl qw(:flock);<br>unless (flock(DATA, LOCK_EX|LOCK_NB)) {<br> &nbsp;&nbsp;&nbsp;&nbsp;exit;<br> &nbsp;&nbsp;&nbsp;&nbsp;print "$0 is already running. Exiting.\n";<br> &nbsp;&nbsp;&nbsp;&nbsp;exit(1);<br>}<br><br><br>and at the very end add:<br><br>__DATA__<br>This exists so flock() code above works.<br>DO NOT REMOVE THIS DATA SECTION.<br><br></div></blockquote></div><br></div></body></html>