1 .\" $NetBSD: shlock.1,v 1.2 1997/10/19 23:08:43 lukem Exp $
8 .Nd create or verify a lock file for shell scripts
19 command can create or verify a lock file on behalf of a shell or
21 When it attempts to create a lock file, if one already exists,
23 verifies that it is or is not valid.
26 will exit with a non-zero exit code.
29 will remove the lock file, and
35 system call to make the final target lock file, which is an atomic
36 operation (i.e. "dot locking", so named for this mechanism's original
37 use for locking system mailboxes).
38 It puts the process ID ("PID") from the command line into the
42 verifies that an extant lock file is still valid by
45 with a zero signal to check for the existence of the process that
58 is given when the program is to create a lock file; when absent,
60 will simply check for the validity of the lock file.
66 to read and write the PID as a binary pid_t, instead of as ASCII,
67 to be compatible with the locks created by UUCP.
73 to be verbose about what it is doing.
75 A zero exit code indicates a valid lock file.
81 if shlock -f ${lckfile} -p $$
83 # do what required the lock
86 echo Lock ${lckfile} already held by `cat ${lckfile}`
92 set lckfile=/tmp/foo.lock
93 shlock -f ${lckfile} -p $$
94 if ($status == 0) then
95 # do what required the lock
98 echo Lock ${lckfile} already held by `cat ${lckfile}`
102 The examples assume that the filesystem where the lock file is to
103 be created is writeable by the user, and has space available.
106 was written for the first Network News Transfer Protocol (NNTP)
107 software distribution, released in March 1986.
108 The algorithm was suggested by Peter Honeyman,
109 from work he did on HoneyDanBer UUCP.
111 Erik E. Fair <fair@clock.org>
113 Does not work on NFS or other network filesystem on different
114 systems because the disparate systems have disjoint PID spaces.
116 Cannot handle the case where a lock file was not deleted, the
117 process that created it has exited, and the system has created a
118 new process with the same PID as in the dead lock file.
119 The lock file will appear to be valid even though the process is
120 unrelated to the one that created the lock in the first place.
121 Always remove your lock files after you're done.