flock
Name
flock -- apply or remove an advisory lock on an open file
Synopsis
int
flock
(int
fd, int
operation);
Description
flock() applies or removes an advisory
lock on the open file fd. Valid
operation types are:
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
oring) along with one of
the other operations. |
A single file may not simultaneously have both shared and exclusive locks.
Return Value
On success, 0 is returned.
On error, -1 is returned and
the global variable errno
is set appropriately.
Errors
EWOULDBLOCK | | The file is locked and the LOCK_NB flag was selected. |
EBADF | | fd is not a not an open file descriptor. |
EINTR | | While waiting to acquire a lock, the call was interrupted by
delivery of a signal caught by a handler. |
EINVAL | | The operation is invalid. |
ENOLCK | | The implementation ran out of memory for allocating lock records. |