| delorie.com/archives/browse.cgi | search |
| X-Spam-Check-By: | sourceware.org |
| Date: | Fri, 21 Apr 2006 16:02:06 -0700 |
| From: | "Jerry D. Hedden" <jerry AT hedden DOT us> |
| Subject: | RE: How to prevent duplicate cron jobs? |
| To: | cygwin AT cygwin DOT com |
| Message-ID: | <20060421160206.fb30e530d17747c2b054d625b8945d88.4b678de279.wbe@email.secureserver.net> |
| MIME-Version: | 1.0 |
| User-Agent: | Web-Based Email 4.1.13 |
| X-IsSubscribed: | yes |
| Mailing-List: | contact cygwin-help AT cygwin DOT com; run by ezmlm |
| List-Subscribe: | <mailto:cygwin-subscribe AT cygwin DOT com> |
| List-Archive: | <http://sourceware.org/ml/cygwin/> |
| List-Post: | <mailto:cygwin AT cygwin DOT com> |
| List-Help: | <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs> |
| Sender: | cygwin-owner AT cygwin DOT com |
| Mail-Followup-To: | cygwin AT cygwin DOT com |
| Delivered-To: | mailing list cygwin AT cygwin DOT com |
> 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/
| webmaster | delorie software privacy |
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |