.\" Copyright 1997 Nicolás Lichtmaier .\" Created Thu Aug 7 00:44:00 ART 1997 .\" .\" This is free documentation; you can redistribute it and/or .\" modify it under the terms of the GNU General Public License as .\" published by the Free Software Foundation; either version 2 of .\" the License, or (at your option) any later version. .\" .\" The GNU General Public License's references to "object code" .\" and "executables" are to be interpreted as the output of any .\" document formatting or typesetting system, including .\" intermediate and printed output. .\" .\" This manual is distributed in the hope that it will be useful, .\" but WITHOUT ANY WARRANTY; without even the implied warranty of .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the .\" GNU General Public License for more details. .\" .TH LOCKF 3 "6 August 1997" "Linux 2.0" "Linux Programmer's Manual" .SH NAME lockf \- apply, test or remove a POSIX lock on an open file .SH SYNOPSIS .B #include .sp .BR "int lockf(int " fd ", int " cmd ", off_t " len ); .SH DESCRIPTION Apply, test or remove a POSIX lock on an open file. The file is specified by .IR fd . This call is just an interface for .BR fcntl "(2)." Valid operations are given below: .RS .sp .TP 1.0i .B F_LOCK Set an exclusive lock to the file. Only one process may hold an exclusive lock for a given file at a given time. If the file is already locked it blocks until the previous lock is released. .TP .B F_TLOCK Same as .B F_LOCK but never blocks and return error instead if the file is already locked. .TP .B F_ULOCK Unlock the file. .TP .B F_TEST Test the lock: return 0 if .I fd is unlocked or locked by this process; return -1, set .I errno to .BR EACCES , if another process holds the lock. .sp .RE .SH "RETURN VALUE" On success, zero is returned. On error, \-1 is returned, and .I errno is set appropriately. .SH ERRORS .TP .B EAGAIN The file is locked and the .B LOCK_NB flag was selected, or operation is prohibited because the file has been memory-mapped by another process. .TP .B EBADF .I fd is not an open file descriptor. .TP .B EDEADLK Specified lock operation would cause a deadlock. .TP .B EINVAL An invalid operation was specified in .IR fd . .TP .B ENOLCK Too many segment locks open, lock table is full. .SH CONFORMING TO SYSV .SH "SEE ALSO" .BR fcntl (2), .BR flock (2). There are also .I locks.txt and .I mandatory.txt in .IR /usr/src/linux/Documentation .