Creating a lock file in sh?
Robert Hartman
rhartman at thestepchild.sgi.com
Thu Apr 18 06:19:31 AEST 1991
In article <PABLO.91Apr17110430 at tofu-hut.csd.sgi.com> pablo at sgi.com (Pablo Sanchez) writes:
>Hey there,
>
> I apologize if this has been hashed over a bizzillion times but can
>someone please send me their Bourne-shell lock-file implementation.
>Thanks.
Aside from the fact that it isn't guaranteed over NFS, you can get some
measure of protection this way:
if [ ! -w $file.lock ] ; then
echo $user: $$ `date` > $file.lock
if [ $$ -eq `awk '{print $2}' $file.lock` ] ; then
# enter protected section
# ...
# exit protected section
else
echo "$file in use" ; exit 1
fi
else
echo "$file in use" ; exit 1
fi
-r
More information about the Comp.unix.shell
mailing list