From owner-freebsd-questions Mon May 4 06:34:56 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id GAA28532 for freebsd-questions-outgoing; Mon, 4 May 1998 06:34:56 -0700 (PDT) (envelope-from owner-freebsd-questions@FreeBSD.ORG) Received: from siafu.iconnect.co.ke (qmailr@siafu.iconnect.co.ke [208.208.120.2]) by hub.freebsd.org (8.8.8/8.8.8) with SMTP id GAA28493 for ; Mon, 4 May 1998 06:34:32 -0700 (PDT) (envelope-from arb@iconnect.co.ke) Received: (qmail 17626 invoked by uid 182); 4 May 1998 13:33:28 -0000 Message-ID: <19980504163327.B4937@iconnect.co.ke> Date: Mon, 4 May 1998 16:33:27 +0300 From: me@anand.org To: hgoldste@bbs.mpcs.com Cc: freebsd-questions@FreeBSD.ORG Subject: Re: Protecting Shell scripts from deadlocks... References: <87zph990m6.fsf@kstreet.interlog.com> <199804261306.JAA20223@bbs.mpcs.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 0.91.1 In-Reply-To: <199804261306.JAA20223@bbs.mpcs.com>; from Howard Goldstein on Sun, Apr 26, 1998 at 09:06:09AM -0400 Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG On Sun, Apr 26, 1998 at 09:06:09AM -0400, Howard Goldstein wrote: > street@iName.com wrote: > : > : There's a little utility called lockfile which is distributed as part > : of procmail that can help with this. It has timeouts and retries and > : lock forcing options that are handy. > > shlock (in the INN distribution) may also be an option. It's > less powerful than lockfile though, lacking timeouts and retries... Yet another way is to create a directory as a lock, instead of a file. Whereas 2 instances of touch can touch a file, only one mkdir can create a directory at any one time. I used to use touch, until a unix guru pointed out this to me. Here's a snippet of code to do this (using /bin/sh) ...... some code ....... if [ -d $HOME/lock ] then echo "Session already running." exit 1 else mkdir $HOME/lock if [ "X$?" = "X0" ] then echo "Lock created" .... some more code ...... rmdir $HOME/lock && echo Lock removed else echo "Oops. Failed to lock. Exiting..." exit 1 fi fi -- Anand To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message