How to prevent duplicate cron jobs?

Jerry D. Hedden jerry@hedden.us
Fri Apr 21 23:59:00 GMT 2006


> 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/



More information about the Cygwin mailing list