This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]