]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - usr.bin/lockf/lockf.1
This commit was generated by cvs2svn to compensate for changes in r146899,
[FreeBSD/FreeBSD.git] / usr.bin / lockf / lockf.1
1 .\"
2 .\" Copyright (C) 1998 John D. Polstra.  All rights reserved.
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
6 .\" are met:
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\"    notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\"    notice, this list of conditions and the following disclaimer in the
11 .\"    documentation and/or other materials provided with the distribution.
12 .\"
13 .\" THIS SOFTWARE IS PROVIDED BY JOHN D. POLSTRA AND CONTRIBUTORS ``AS IS'' AND
14 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 .\" ARE DISCLAIMED.  IN NO EVENT SHALL JOHN D. POLSTRA OR CONTRIBUTORS BE LIABLE
17 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23 .\" SUCH DAMAGE.
24 .\"
25 .\" $FreeBSD$
26 .\"
27 .Dd July 7, 1998
28 .Os
29 .Dt LOCKF 1
30 .Sh NAME
31 .Nm lockf
32 .Nd execute a command while holding a file lock
33 .Sh SYNOPSIS
34 .Nm
35 .Op Fl ks
36 .Op Fl t Ar seconds
37 .Ar file
38 .Ar command
39 .Op Ar arguments
40 .Sh DESCRIPTION
41 The
42 .Nm
43 utility acquires an exclusive lock on a
44 .Ar file ,
45 creating it if necessary,
46 .Em "and removing the file on exit unless explictly told not to."
47 While holding the lock, it executes a
48 .Ar command
49 with optional
50 .Ar arguments .
51 After the
52 .Ar command
53 completes,
54 .Nm
55 releases the lock, and removes the
56 .Ar file
57 unless the
58 .Fl k
59 option is specified.
60 .Bx Ns -style
61 locking is used, as described in
62 .Xr flock 2 ;
63 the mere existence of the
64 .Ar file
65 is not considered to constitute a lock.
66 .Pp
67 The following options are supported:
68 .Bl -tag -width Fl
69 .It Fl k
70 Causes the lock file to be kept (not removed) after the command
71 completes.
72 .It Fl s
73 Causes
74 .Nm
75 to operate silently.
76 Failure to acquire the lock is indicated only in the exit status.
77 .It Fl t Ar seconds
78 Specifies a timeout for waiting for the lock.
79 By default,
80 .Nm
81 waits indefinitely to acquire the lock.
82 If a timeout is specified with this option,
83 .Nm
84 will wait at most the given number of
85 .Ar seconds
86 before giving up.
87 A timeout of 0 may be given, in which case
88 .Nm
89 will fail unless it can acquire the lock immediately.
90 When a lock times out,
91 .Ar command
92 is
93 .Em not
94 executed.
95 .El
96 .Pp
97 In no event will
98 .Nm
99 break a lock that is held by another process.
100 .Sh EXIT STATUS
101 If
102 .Nm
103 successfully acquires the lock, it returns the exit status produced by
104 .Ar command .
105 Otherwise, it returns one of the exit codes defined in
106 .Xr sysexits 3 ,
107 as follows:
108 .Bl -tag -width F_CANTCREATX
109 .It Dv EX_TEMPFAIL
110 The specified lock file was already locked by another process.
111 .It Dv EX_CANTCREAT
112 The
113 .Nm
114 utility
115 was unable to create the lock file, e.g., because of insufficient access
116 privileges.
117 .It Dv EX_USAGE
118 There was an error on the
119 .Nm
120 command line.
121 .It Dv EX_OSERR
122 A system call (e.g., fork) failed unexpectedly.
123 .El
124 .Sh SEE ALSO
125 .Xr flock 2 ,
126 .Xr sysexits 3
127 .Sh HISTORY
128 A
129 .Nm
130 utility first appeared in
131 .Fx 2.2 .
132 .Sh AUTHORS
133 .An John Polstra Aq jdp@polstra.com .