Pathologically Eclectic Rubbish Lister | |
PerlMonks |
Re^3: Cron Jobs That Run For Too Longby adamk (Chaplain) |
on Dec 20, 2005 at 23:22 UTC ( [id://518209]=note: print w/replies, xml ) | Need Help?? |
But wait, it gets better again! You know how you can have that nifty __DATA__ block at the end of your script? It turns out you can lock that too :) I've used this a number of times and it works just great. #!/usr/bin/perl use strict; use Fcntl 'LOCK_EX', 'LOCK_NB'; unless ( flock DATA, LOCK_EX | LOCK_NB ) { print STDERR "Found duplicate script run. Stopping\n"; exit(0); } ... 1; ### DO NOT REMOVE THE FOLLOWING LINES ### __DATA__ This exists to allow the locking code at the beginning of the file to work. DO NOT REMOVE THESE LINES!
In Section
Seekers of Perl Wisdom
|
|