[Tutor] Lock File Usage

Alan Gauld alan.gauld at yahoo.co.uk
Mon Jan 30 13:15:48 EST 2017

On 30/01/17 14:45, ad^2 wrote:

>  So, IF: no lock file, create a lock file, execute, delete lock file when
> finished successfully. ElSE: the script is running, exit. Then, cron will
> try again an hour later.

That's probably the most common way of doing what you want.
But you need to make absolutely sure you delete the old file
after you are done, even in the event of failures.

try/finally at the top level would vbe a good start.

But many also use a second cron job to check for files older
than, say, T+50% (or whatever is the worst case) and then
either delete them or flag a warning to the admins to check.
This can run before the batch job that uses the files starts.
You may accidentally miss one run but you should never miss
more than that.

Alan G
Author of the Learn to Program web site
Follow my photo-blog on Flickr at:

More information about the Tutor mailing list