]> git.ipfire.org Git - thirdparty/util-linux.git/blob - sys-utils/flock.1
Imported from util-linux-2.13-pre7 tarball.
[thirdparty/util-linux.git] / sys-utils / flock.1
1 .\" $Id: flock.1,v 1.3 2006/02/04 20:41:57 hpa Exp $
2 .\" -----------------------------------------------------------------------
3 .\"
4 .\" Copyright 2003-2006 H. Peter Anvin - All Rights Reserved
5 .\"
6 .\" Permission is hereby granted, free of charge, to any person
7 .\" obtaining a copy of this software and associated documentation
8 .\" files (the "Software"), to deal in the Software without
9 .\" restriction, including without limitation the rights to use,
10 .\" copy, modify, merge, publish, distribute, sublicense, and/or
11 .\" sell copies of the Software, and to permit persons to whom
12 .\" the Software is furnished to do so, subject to the following
13 .\" conditions:
14 .\"
15 .\" The above copyright notice and this permission notice shall
16 .\" be included in all copies or substantial portions of the Software.
17 .\"
18 .\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 .\" EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20 .\" OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 .\" NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22 .\" HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 .\" WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 .\" FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25 .\" OTHER DEALINGS IN THE SOFTWARE.
26 .\"
27 .\" -----------------------------------------------------------------------
28 .TH FLOCK "1" "4 Feb 2006" "flock utility" "H. Peter Anvin"
29 .SH NAME
30 flock \- Manage locks from shell scripts
31 .SH SYNOPSIS
32 \fBflock\fP [\fB\-sxon\fP] [\fB\-w\fP \fItimeout\fP] \fIlockfile\fP [\fB\-c\fP] \fIcommand...\fP
33 .PP
34 \fBflock\fP [\fB\-sxun\fP] [\fB\-w\fP \fItimeout\fP] \fIfd\fP
35 .SH DESCRIPTION
36 .PP
37 This utility manages
38 .BR flock (2)
39 locks from within shell scripts or the command line.
40 .PP
41 The first form wraps the lock around the executing a command, in a manner similar to
42 .BR su (1)
43 or
44 .BR newgrp (1).
45 It locks a specified file, which is created (assuming appropriate
46 permissions), if it does not already exist.
47 .PP
48 The second form is conveninent inside shell scripts, and is usually
49 used the following manner:
50 .PP
51 \fC(
52 .br
53 flock -s 200
54 .br
55 # ... commands executed under lock ...
56 .br
57 ) 200>/var/lock/mylockfile\fP
58 .PP
59 The mode used to open the file doesn't matter to \fBflock\fP; using
60 \fC>\fP or \fP>>\fP allows the lockfile to be created if it does not
61 already exist, however, write permission is required; using \fC<\fP
62 requires that the file already exists but only read permission is
63 required.
64 .PP
65 By default, if the lock cannot be immediately acquired, \fBflock\fP
66 waits until the lock is available.
67 .SH OPTIONS
68 .TP
69 \fB\-s\fP, \fB\-\-shared\fP
70 Obtain a shared lock, sometimes called a read lock.
71 .TP
72 \fB\-x\fP, \fB\-e\fP, \fB\-\-exclusive\fP
73 Obtain an exclusive lock, sometimes called a write lock. This is the
74 default.
75 .TP
76 \fB\-u\fP, \fB\-\-unlock\fP
77 Drop a lock. This is usually not required, since a lock is
78 automatically dropped when the file is closed. However, it may be
79 required in special cases, for example if the enclosed command group
80 may have forked a background process which should not be holding the
81 lock.
82 .TP
83 \fB\-n\fP, \fB\-\-nb\fP, \fB\-\-nonblock\fP
84 Fail (with an exit code of 1) rather than wait if the lock cannot be
85 immediately acquired.
86 .TP
87 \fB\-w\fP, \fB\-\-wait\fP, \fB\-\-timeout\fP \fIseconds\fP
88 Fail (with an exit code of 1) if the lock cannot be acquired within
89 \fIseconds\fP seconds. Decimal fractional values are allowed.
90 .TP
91 \fB\-o\fP, \fB\-\-close\fP
92 Close the file descriptor on which the lock is held before executing
93 \fIcommand\fP. This is useful if \fIcommand\fP spawns a child process
94 which should not be hold ing the lock.
95 .TP
96 \fB\-c\fP, \fB\-\-command\fP \fIcommand\fP
97 Pass a single \fIcommand\fP to the shell with \fB\-c\fP.
98 .TP
99 \fB\-h\fP, \fB\-\-help\fP
100 Print a help message.
101 .SH AUTHOR
102 Written by H. Peter Anvin <hpa@zytor.com>.
103 .SH COPYRIGHT
104 Copyright \(co 2003\-2006 H. Peter Anvin.
105 .br
106 This is free software; see the source for copying conditions. There is NO
107 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
108 .SH "SEE ALSO"
109 .BR flock (2)