Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 2 Sep 2008 11:40:37 -0500
From:      Dan Nelson <dnelson@allantgroup.com>
To:        Paul Schmehl <pschmehl_lists_nada@tx.rr.com>
Cc:        Albert.Shih@obspm.fr, ElihuJ <chinocubus@yahoo.com>, freebsd-questions@freebsd.org
Subject:   Re: Cron Question
Message-ID:  <20080902164037.GM26653@dan.emsphone.com>
In-Reply-To: <D59C3198F12C06340437288A@Macintosh.local>
References:  <19272656.post@talk.nabble.com> <20080902160351.GI79391@pcjas.obspm.fr> <D59C3198F12C06340437288A@Macintosh.local>

next in thread | previous in thread | raw e-mail | index | archive | help
In the last episode (Sep 02), Paul Schmehl said:
> --On September 2, 2008 6:03:51 PM +0200 Albert Shih wrote:
> >  Le 02/09/2008 à 08:45:52-0700, ElihuJ a écrit
> >> Hi all. I have a question about cron jobs that seem to be running
> >> to long or with multiple copies of itself. For example, I have a
> >> backup script that I run that seems to make multiple copies of
> >> itself. If I view the running processes I see numerous instances
> >> of the same cron job. Is there something I can do to limit this
> >> from happening? When it does, it drains my CPU and some of my
> >> other processes are non responsive. Any help would be appreciated.
> >> Thank you.
> >
> > That's not the to cron to do that.
> 
> Actually, it could be.  If the script is started by cron and is still
> running when the next job is scheduled, cron will start another
> process.  If they're both still running when the next job is
> scheduled, you'll have three processes running, etc., etc.

I use the lockfile command ( from the procmail port ) to ensure that
recurring cron jobs don't overlap if one run takes too long. For
example, to run mrtg on a 1-minute cycle but prevent multiple mrtgs
from running if one run takes longer than 1 minute:

* * * * * /usr/local/bin/lockfile -r 1 -l 3600 /tmp/mrtg.LCK && ( nice -19 /usr/local/bin/mrtg /usr/local/etc/mrtg/mrtg.cfg ; rm /tmp/mrtg.LCK )

The -l 3600 tells lockfile to remove any lockfiles over an hour old (
if the machine was rebooted during an mrtg run for example )

-- 
	Dan Nelson
	dnelson@allantgroup.com



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20080902164037.GM26653>