Skip site navigation (1)Skip section navigation (2)
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...
Message-ID:  <19980504163327.B4937@iconnect.co.ke>
In-Reply-To: <199804261306.JAA20223@bbs.mpcs.com>; from Howard Goldstein on Sun, Apr 26, 1998 at 09:06:09AM -0400
References:  <87zph990m6.fsf@kstreet.interlog.com> <199804261306.JAA20223@bbs.mpcs.com>

next in thread | previous in thread | raw e-mail | index | archive | help
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



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