1.\" 2.\" Copyright (C) 1997 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.\" $Id$ 26.\" 27.Dd January 8, 1997 28.Os FreeBSD 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 s 36.Op Fl t Ar seconds 37.Ar file 38.Ar command 39.Op Ar arguments 40.Sh DESCRIPTION 41The 42.Nm 43utility acquires an exclusive lock on a 44.Ar file , 45creating it if necessary. 46While holding the lock, it executes a 47.Ar command 48with optional 49.Ar arguments . 50After the 51.Ar command 52completes, 53.Nm 54releases the lock and removes the 55.Ar file . 56BSD-style locking is used, as described in 57.Xr flock 2 ; 58the mere existence of the 59.Ar file 60is not considered to constitute a lock. 61.Pp 62The following options are supported: 63.Bl -tag -width Fl 64.It Fl s 65Causes 66.Nm 67to operate silently. 68Failure to acquire the lock is indicated only in the exit status. 69.It Fl t Ar seconds 70Specifies a timeout for waiting for the lock. By default, 71.Nm 72waits indefinitely to acquire the lock. 73If a timeout is specified with this option, 74.Nm 75will wait at most the given number of 76.Ar seconds 77before giving up. A timeout of 0 may be given, in which case 78.Nm 79will fail unless it can acquire the lock immediately. 80.El 81.Pp 82In no event will 83.Nm 84break a lock that is held by another process. 85.Sh DIAGNOSTICS 86If 87.Nm 88successfully acquires the lock, it returns the exit status produced by 89.Ar command . 90Otherwise, it returns one of the exit codes defined in 91.Xr sysexits 3 , 92as follows: 93.Bl -tag -width F_CANTCREATX 94.It Dv EX_TEMPFAIL 95The specified lock file was already locked by another process. 96.It Dv EX_CANTCREAT 97.Nm 98was unable to create the lock file, e.g., because of insufficient access 99privileges. 100.It Dv EX_USAGE 101There was an error on the 102.Nm 103command line. 104.It Dv EX_OSERR 105A system call (e.g., fork) failed unexpectedly. 106.El 107.Sh SEE ALSO 108.Xr flock 2 , 109.Xr sysexits 3 . 110.Sh AUTHORS 111John Polstra, 112.Aq jdp@polstra.com . 113