Table of Contentsflock - apply or remove an advisory lock on an open file #include <sys/file.h> int flock(int fd, int operation)
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, dup(2) and fork(2) do not create multiple instances of a lock.
On success, zero is returned. On error, -1 is returned, and errno is set appropriately. - EWOULDBLOCK
- The file is locked an the LOCK_NB flag was selected.
Under Linux, flock is implemented as a call to fcntl. Please see fcntl(2) for more details on errors. open(2), close(2), dup(2), execve(2), fcntl(2), fork(2),
Table of Contents
www.fiveanddime.net