This is the mail archive of the
cygwin
mailing list for the Cygwin project.
RE: How to prevent duplicate cron jobs?
- From: "Jerry D. Hedden" <jerry at hedden dot us>
- To: cygwin at cygwin dot com
- Date: Fri, 21 Apr 2006 16:02:06 -0700
- Subject: RE: How to prevent duplicate cron jobs?
> I have a cron job running perl and it is taking a very long time --
> sometimes over 24 hours.
>
> How can I have cron schedule my job daily, or even hourly, and have
> the perl code exit if a previouse instance of the job is still
> running?
Use Proc::Daemon in conjunction with Proc::PID::File. Both can be found
on CPAN.
#!/usr/bin/perl
use strict;
use warnings;
use Proc::Daemon;
use Proc::PID::File;
MAIN:
{
# Daemonize
Proc::Daemon::Init();
# If already running, then exit
if (Proc::PID::File->running()) {
exit(0);
}
# Do work
....
}
exit(0);
# EOF
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/