.\" As its sole author, I explicitly place this file in the public domain. .\" It may be used by anyone in any way for any purpose, though I would .\" appreciate credit where it's due. .\" der Mouse, mouse@rodents.montreal.qc.ca, 1999-10-13 .Dd October 3, 2007 .Dt FLOCK 1 .Os NetBSD 1.4 .Sh NAME .Nm flock .Nd file-locking command-line tool .Sh SYNOPSIS .Nm .Op Fl sh .Op Fl ex .Op Fl nb .Op Fl un .Op Fl v .Ar fd .Sh DESCRIPTION .Nm is a small command-line interface to .Xr flock 2 . It is normally used to provide clean and reliable locking from shell scripts, something that is otherwise rather difficult. .Pp The .Ar fd argument specifies the file descriptor the locking operation is applied to. (This will normally be a descriptor held open by the shell script, since otherwise the lock is not persistent, though testing using .Fl nb can be useful with transient descriptors.) The .Fl sh , .Fl ex , .Fl nb , and .Fl un flags specify what kind of locking operation is to be performed; they correspond to the similarly-named bits in the second argument to .Xr flock 2 (for example, specifying .Fl sh results in the call to .Xr flock 2 using .Dv LOCK_SH ) . .Pp The exit status is 0 (success) if the .Xr flock 2 operation succeeded, 1 (failure) if the attempt failed with error .Ev EAGAIN , or 2 in case of other failures or problems such as invalid arguments. Conditions that produce exit status 2 always print messages; exit status 1 is normally silent, but with .Fl v it is accompanied by a message to stderr giving the error reason message (see .Xr strerror 3 ) . .Sh SEE ALSO .Xr flock 2 , .Xr lseek 1 , .Xr strerror 3 .Sh AUTHOR der Mouse, .Aq mouse@rodents.montreal.qc.ca .