>>>>> ""siegfried"" == "siegfried"  <[EMAIL PROTECTED]> writes:

"siegfried"> How can I have cron schedule my job daily, or even hourly, and 
have the perl
"siegfried"> code  exit if a previouse instance of the job is still running?

"There can be only one!" - The Highlander Solution, as described in
<http://www.stonehenge.com/merlyn/WebTechniques/col54.html>.

But the short version is this:

(1) make sure you have __END__ at the end of your program (so DATA is valid)
(2) at the beginning of your program, insert:

  use Fcntl qw(LOCK_EX LOCK_NB);
  flock(DATA, LOCK_EX | LOCK_NB) or exit 0;

And now you'll have only one instance running, ever.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to