|FLOCK(3C)||Standard C Library Functions||FLOCK(3C)|
#include <sys/file.h> int flock(int fildes, int operation);
The fildes argument is an open file descriptor. A lock can be established without regard for the mode with which the file was opened.
The operation argument is a control value that specifies the action to be taken. The permissible values for operation are defined in <sys/file.h> as follows:
#define LOCK_SH 1 /* shared file lock */ #define LOCK_EX 2 /* exclusive file lock */ #define LOCK_NB 4 /* do not block when attempting to create lock */ #define LOCK_UN 8 /* remove existing file lock */
To create a lock, either LOCK_SH or LOCK_EX should be specified, optionally bitwise-ored with LOCK_NB. To remove a lock, LOCK_UN should be specified. All other values of operation are reserved for future extensions and will result in an error if not implemented.
This function creates, upgrades, downgrades, or removes either shared or exclusive OFD-style locks. Locks created by this function are owned by open files, not file descriptors. That is, file descriptors duplicated through dup(2), fork(2), or fcntl(2) do not result in multiple instances of a lock, but rather multiple references to the same lock. If a process holding a lock on a file forks and the child explicitly unlocks the file, the parent will lose its lock. See fcntl(2) for more information about file locking and the interaction between locks created by this function and those created by other mechanisms. These locks are currently not supported over remote file systems (e.g. nfs(5)) which use the Network Lock Manager.
Sleeping on a resource is interrupted with any signal. The alarm(2) function may be used to provide a timeout facility in applications that require this facility.
The flock() function may fail if:
The alarm(2) function may be used to provide a timeout facility in applications requiring it.
Locks created by this facility conflict with those created by the lockf(3C) and fcntl(2) facilities. This facility creates and removed OFD-style locks; see fcntl(2) for information about the interaction between OFD-style and POSIX-style file locks.
|ATTRIBUTE TYPE||ATTRIBUTE VALUE|
|February 16, 2015||OmniOS|