From owner-freebsd-questions@FreeBSD.ORG Tue Sep 2 16:40:41 2008 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D32281065675 for ; Tue, 2 Sep 2008 16:40:41 +0000 (UTC) (envelope-from dan@dan.emsphone.com) Received: from dan.emsphone.com (dan.emsphone.com [199.67.51.101]) by mx1.freebsd.org (Postfix) with ESMTP id 981038FC1E for ; Tue, 2 Sep 2008 16:40:41 +0000 (UTC) (envelope-from dan@dan.emsphone.com) Received: from dan.emsphone.com (smmsp@localhost [127.0.0.1]) by dan.emsphone.com (8.14.3/8.14.3) with ESMTP id m82GedBZ032953 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Tue, 2 Sep 2008 11:40:39 -0500 (CDT) (envelope-from dan@dan.emsphone.com) Received: (from dan@localhost) by dan.emsphone.com (8.14.3/8.14.2/Submit) id m82GebGt032948; Tue, 2 Sep 2008 11:40:37 -0500 (CDT) (envelope-from dan) Date: Tue, 2 Sep 2008 11:40:37 -0500 From: Dan Nelson To: Paul Schmehl Message-ID: <20080902164037.GM26653@dan.emsphone.com> References: <19272656.post@talk.nabble.com> <20080902160351.GI79391@pcjas.obspm.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-OS: FreeBSD 7.0-STABLE User-Agent: Mutt/1.5.18 (2008-05-17) Cc: Albert.Shih@obspm.fr, ElihuJ , freebsd-questions@freebsd.org Subject: Re: Cron Question X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 02 Sep 2008 16:40:41 -0000 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