OSDN Git Service

Import translated manuals from JM CVS Repository.
[linuxjm/jm.git] / manual / util-linux / original / man1 / flock.1
1 .TH FLOCK "1" "November 2004" "flock (util-linux)" "User Commands"
2 .SH NAME
3 flock \- acquire a file lock and then execute a command with the lock held
4 .SH SYNOPSIS
5 .BR flock
6 [ \fB\-\-shared\fR | \fB\-\-timeout=\fR\fIseconds\fR ] lockfile command ..
7 .SH DESCRIPTION
8 .\" Add any additional description here
9 .PP
10 Acquire a file lock using the flock(2) system call and then execute
11 the given command with the lock held.  Depending on the options given,
12 the lock can be either exclusive or shared, and the behavior in the
13 event of lock contention can be specified as either waiting
14 indefinitely for the lock to become available (the default), or
15 failing if the lock does not become available after a specific time,
16 which can be specified as zero to make the command not wait at all.
17 .PP
18 .TP
19 \fB\-\-shared\fR
20 Acquire a shared lock.  Acquiring a shared lock does
21 not stop others from acquiring a shared lock, but it will stop others
22 from acquiring an exclusive lock.  Conversely, acquiring an exclusive
23 lock (the default) stops both exclusive and shared attempts to acquire
24 the lock.  Typically, a shared lock is used if a command is just going
25 to read the locked data, and an exclusive lock is used if the command
26 might write to it.
27 .TP
28 \fB\-\-timeout=n\fR
29 Abort if the lock cannot be acquired before \fIn\fR seconds.
30 For a completely non-blocking attempt to acquire a lock, specify
31 \fB\-\-timeout=0\fR.
32 The timer applies only to the attempt to acquire the lock.  As soon
33 as the lock is acquired, the timeout is cancelled.  The command to
34 be run is not subject to the timeout.
35 .PP
36 .SH "EXAMPLES (invoking some imaginary programs)"
37 .hl
38 .PP
39 flock /etc/passwd read-and-write-to-passwd
40 .PP
41 flock \-\-shared /etc/passwd just-read-something-from-passwd
42 .PP
43 flock \-\-timeout=0 /sys /usr/local/bin/update-hotplug /sys
44 .SH AUTHOR
45 Written by Adam J. Richter