chiark / gitweb /
Release 1.2.9.1.
[misc] / locking.1
... / ...
CommitLineData
1.TH "locking" 1 "11 May 2003" "Mark Wooding" "Toys"
2.SH NAME
3locking \- run a program with a lock held
4.
5.SH SYNOPSIS
6.B locking
7.RB [ \-cfwx ]
8.RB [ \-p
9.IR realprog ]
10.RB [ \-t
11.IR time ]
12.I file
13.I prog
14.IR args ...
15.
16.SH "DESCRIPTION"
17The
18.B locking
19program opens and locks
20.I file
21while it runs some program
22.IR prog .
23This is handy in shell scripts and (particularly) crontab entries. It
24was initially written to ensure that news fetches only occurred if the
25previous one had completed.
26.PP
27The program uses
28.BR fcntl (2)-style
29locking. It will not leave stale locks lying around: the lock is
30released if
31.I prog
32or the
33.B locking
34program itself quits for any reason.
35.PP
36The following options are supported:
37.TP
38.B "\-h, \-\-help"
39Write a full help message to stdout, and exit zero.
40.TP
41.B "\-v, \-\-version"
42Write the version number to stdout, and exit zero.
43.TP
44.B "\-u, \-\-usage"
45Write a brief usage message to stdout, and exit zero.
46.TP
47.BR "\-c, \-\-" [ "no\-" ] "create"
48Create
49.I file
50if it doesn't already exist. The file is created with mode 666 as
51modified by the process's umask in the usual way. This is the default
52behaviour. The options
53.B +c
54or
55.B \-\-no\-create
56will cause
57.B locking
58to fail if the file does not already exist.
59.TP
60.BR "\-f, \-\-" [ "no\-" ] "fail"
61Fail (report an error and exit nonzero) if
62.I file
63is already locked. The default behaviour is to exit successfully
64without running
65.IR prog .
66.TP
67.BR "\-w, \-\-" [ "no\-" ] "wait"
68Wait for the lock on
69.I file
70to become available. The default behaviour is to give up immediately.
71.TP
72.BR "\-x, \-\-" [ "no\-" ] "exclusive"
73Obtain an exclusive lock on the file. This is the default. The options
74.B +x
75or
76.B \-\-no\-exclusive
77obtain a non-exclusive lock on the file instead.
78.TP
79.BI "\-p, \-\-program=" realprog
80Run the program
81.IR realprog ,
82passing it
83.I prog
84as its first argument. The default behaviour is to run
85.IR prog .
86.TP
87.BI "\-t, \-\-timeout=" time
88Wait for
89.I time
90(an integer, optionally followed by
91.RB ` d ',
92.RB ` h ',
93.RB ` m ',
94or
95.RB ` s '
96for days, hours, minutes or seconds, respectively) for the lock to
97become available, and then give up. This only makes sense with the
98.B \-\-wait
99option, so that is turned on automatically.
100.SH "BUGS"
101The
102.B locking
103program messes with alarms. It tries to put them back the way it found
104them, but may get things wrong.
105.
106.SH "AUTHOR"
107Mark Wooding, <mdw@distorted.org.uk>