.\" $Revision: 5794 $ .TH SHLOCK 1 .SH NAME shlock \- create lock files for use in shell scripts .SH SYNOPSIS .B shlock .BI \-p " pid" .BI \-f " name" [ .B \-b ] [ .B \-u ] [ .B \-c ] .SH DESCRIPTION .I Shlock tries to create a lock file named .I name and write the process ID .I pid into it. If the file already exists, .I shlock will read the process ID from the file and test to see if the process is currently running. If the process exists, then the file will not be created. .PP .I Shlock exits with a zero status if it was able to create the lock file, or non-zero if the file refers to currently-active process. .SH OPTIONS .TP .B \-b Process IDs are normally read and written in ASCII. If the ``\-b'' flag is used, then they will be written as a binary .IR int . For compatibility with other systems, the ``\-u'' flag is accepted as a synonym for ``\-b'' since binary locks are used by many UUCP packages. .TP .B \-c If the ``\-c'' flag is used, then .I shlock will not create a lock file, but will instead use the file to see if the lock is held by another program. If the lock is valid, the program will exit with a non-zero status; if the lock is not valid (i.e., invoking .I shlock without the flag would have succeeded), then the program will exit with a zero status. .SH EXAMPLES The following example shows how .I shlock would be used within a shell script: .RS .nf LOCK=/LOCK.send trap 'rm -f ${LOCK} ; exit 1' 1 2 3 15 if shlock -p $$ -f ${LOCK} ; then # Do appropriate work else echo Locked by `cat ${LOCK}` f\&i .fi .RE .SH BUGS .I shlock assumes that it will not be used in an environment with multiple locks/unlocks in a short time (due to a race condition). That is, .I shlock is intended for daily or hourly jobs. .SH HISTORY Written by Rich $alz after a description of HDB UUCP locking given by Peter Honeyman. .de R$ This is revision \\$3, dated \\$4. .. .R$ $Id: shlock.1 5794 2002-10-01 23:31:53Z vinocur $ .SH "SEE ALSO" inn.conf(5)