xref: /netbsd-src/usr.bin/flock/flock.1 (revision 5e583655578fff99c64cac3256579bc08228d612)
1*5e583655Suwe.\"	$NetBSD: flock.1,v 1.13 2019/10/04 16:14:05 uwe Exp $
2dcdc302cSchristos.\"
3dcdc302cSchristos.\" Copyright (c) 2012 The NetBSD Foundation, Inc.
4dcdc302cSchristos.\" All rights reserved.
5dcdc302cSchristos.\"
6dcdc302cSchristos.\" This code is derived from software contributed to The NetBSD Foundation
7dcdc302cSchristos.\" by Christos Zoulas.
8dcdc302cSchristos.\"
9dcdc302cSchristos.\" Redistribution and use in source and binary forms, with or without
10dcdc302cSchristos.\" modification, are permitted provided that the following conditions
11dcdc302cSchristos.\" are met:
12dcdc302cSchristos.\" 1. Redistributions of source code must retain the above copyright
13dcdc302cSchristos.\"    notice, this list of conditions and the following disclaimer.
14dcdc302cSchristos.\" 2. Redistributions in binary form must reproduce the above copyright
15dcdc302cSchristos.\"    notice, this list of conditions and the following disclaimer in the
16dcdc302cSchristos.\"    documentation and/or other materials provided with the distribution.
17dcdc302cSchristos.\"
18dcdc302cSchristos.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19dcdc302cSchristos.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20dcdc302cSchristos.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21dcdc302cSchristos.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22dcdc302cSchristos.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23dcdc302cSchristos.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24dcdc302cSchristos.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25dcdc302cSchristos.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26dcdc302cSchristos.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27dcdc302cSchristos.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28dcdc302cSchristos.\" POSSIBILITY OF SUCH DAMAGE.
29dcdc302cSchristos.\"
30dcdc302cSchristos.\"
31*5e583655Suwe.Dd October 4, 2019
325f8f0b4dSwiz.Dt FLOCK 1
33dcdc302cSchristos.Os
34dcdc302cSchristos.Sh NAME
35dcdc302cSchristos.Nm flock
36dcdc302cSchristos.Nd Provide locking API for shell scripts
37dcdc302cSchristos.Sh SYNOPSIS
38*5e583655Suwe.\"
39dcdc302cSchristos.Nm
405f8f0b4dSwiz.Op Fl dnosvx
41dcdc302cSchristos.Op Fl w Ar timeout
42*5e583655Suwe.Ar file Ns \^|\^ Ns Ar directory
43*5e583655Suwe.Ar command
44*5e583655Suwe.Op Ar args No ...
45*5e583655Suwe.\"
46*5e583655Suwe.Nm
47*5e583655Suwe.Op Fl dnosvx
48*5e583655Suwe.Op Fl w Ar timeout
49*5e583655Suwe.Ar file Ns \^|\^ Ns Ar directory
50*5e583655Suwe.Fl c Ar command
51*5e583655Suwe.\"
52dcdc302cSchristos.Nm
535f8f0b4dSwiz.Op Fl dnsuvx
54dcdc302cSchristos.Op Fl w Ar timeout
55*5e583655Suwe.Ar number
56dcdc302cSchristos.Sh DESCRIPTION
57dcdc302cSchristosThe
58dcdc302cSchristos.Nm
59dcdc302cSchristosutility provides
60dcdc302cSchristos.Xr flock 2
61dcdc302cSchristosaccess to the command line or scripts.
62*5e583655SuweThe first two forms lock the specified
63*5e583655Suwe.Ar file
64*5e583655Suweor
65*5e583655Suwe.Ar directory
66*5e583655Suwewhile the provided command is executed.
67*5e583655SuweIf the path does not exist, then a file of that name is created with
68*5e583655Suwemode 0600.
69dcdc302cSchristos.Pp
70*5e583655SuweThe third form can use an arbitrary file descriptor
71*5e583655Suwe.Ar number
72*5e583655Suwethat is provided from a shell script for example:
73612f4075Suwe.Bd -literal -offset indent
74dcdc302cSchristos(
75dcdc302cSchristos	flock -s 100
76dcdc302cSchristos	# commands to be executed under the lock
77dcdc302cSchristos) 100> /path/to/lockfile
785f8f0b4dSwiz.Ed
79dcdc302cSchristos.Pp
80dcdc302cSchristosThe following options are available:
81612f4075Suwe.Bl -tag -width Fl
82dcdc302cSchristos.It Fl c Ar command
83dcdc302cSchristosPass a command to a the shell.
845f8f0b4dSwiz.It Fl d , Fl Fl debug
85dcdc302cSchristosProvide debugging output.
865f8f0b4dSwiz.It Fl n , Fl Fl nb , Fl Fl nonblock
875f8f0b4dSwizDon't block and fail immediately if the lock could not be obtained.
885f8f0b4dSwiz.It Fl o , Fl Fl close
895f8f0b4dSwizClose the file before executing the command.
905f8f0b4dSwizThis is useful if the child forks and should not be holding the lock.
915f8f0b4dSwiz.It Fl s , Fl Fl shared
92dcdc302cSchristosObtain a shared lock.
935f8f0b4dSwiz.It Fl u , Fl Fl unlock
94dcdc302cSchristosUnlock an existing lock.
95dcdc302cSchristosThis is available only for a file descriptor.
965f8f0b4dSwiz.It Fl v , Fl Fl verbose
97dcdc302cSchristosOn error print an explanation of the failure.
985f8f0b4dSwiz.It Fl w , Fl Fl wait , Fl Fl timeout Ar seconds
99dcdc302cSchristosFail if the lock could not be obtained after
100dcdc302cSchristos.Ar seconds .
1015f8f0b4dSwiz.It Fl x , Fl Fl exclusive
1025f8f0b4dSwizObtain an exclusive lock.
1035e59f268SchristosThis is the default.
104dcdc302cSchristos.El
105dcdc302cSchristos.Sh EXIT STATUS
106dcdc302cSchristos.Ex -std
107dcdc302cSchristos.Sh SEE ALSO
108e516fe98Swiz.Xr shlock 1 ,
109dcdc302cSchristos.Xr flock 2
110dcdc302cSchristos.Sh HISTORY
1115f8f0b4dSwizAn
112dcdc302cSchristos.Nm
113dcdc302cSchristosutility appeared in
11477b82c32Skhorben.Nx 6.1 .
115