 |
Manpage of FLOCK
FLOCK
Section: Linux Programmer's Manual (2) Updated: 11 December 2025 Index
NAME
flock - apply or remove an advisory lock on an open file
SYNOPSIS
#include <sys/file.h>
int flock(int fd, int operation)
DESCRIPTION
Apply or remove an advisory lock on an open file. The file is specified by
fd.
Valid operations are given below:
-
- LOCK_SH
-
Shared lock. More than one process may hold a shared lock for a given file
at a given time.
- LOCK_EX
-
Exclusive lock. Only one process may hold an exclusive lock for a given
file at a given time.
- LOCK_UN
-
Unlock.
- LOCK_NB
-
Don't block when locking. May be specified (by
or'ing)
along with one of the other operations.
A single file may not simultaneously have both shared and exclusive locks.
A file is locked (i.e., the inode),
not
the file descriptor. So,
and
do not create multiple instances of a lock.
RETURN VALUE
On success, zero is returned. On error, -1 is returned, and
errno
is set appropriately.
ERRORS
- EWOULDBLOCK
-
The file is locked and the
LOCK_NB
flag was selected.
CONFORMING TO
4.4BSD (the
call first appeared in 4.2BSD).
NOTES
does not lock files over NFS. Use
instead: that does work over NFS, given a sufficiently recent version of
Linux and a server which supports locking.
and
locks have different semantics with respect to forked processes and
SEE ALSO
There are also
locks.txt
and
mandatory.txt
in
/usr/src/linux/Documentation.
Index
- NAME
-
- SYNOPSIS
-
- DESCRIPTION
-
- RETURN VALUE
-
- ERRORS
-
- CONFORMING TO
-
- NOTES
-
- SEE ALSO
-
This document was created by
using the manual pages.
Time: 11:56:05 GMT, March 24, 2025
|
 |