#include <fcntl.h>
int fcntl (fildes, cmd, arg) int fildes, cmd;
The commands available are:
The following commands are used for file-locking and record-locking. Locks may be placed on an entire file or segments of a may exist for a given segment of a file at a given time. The file descriptor on which a write lock is being placed must have been opened with write access.
The structure flock defined in the <fcntl.h> header file describes a lock. It describes the type (l_type), starting offset (l_whence), relative offset (l_start), size (l_len), and process-ID (l_pid):
short l_type; /* F_RDLCK, F_WRLCK, F_UNLCK */ short l_whence; /* flag for starting offset */ long l_start; /* relative offset in bytes */ long l_len; /* if 0 then until EOF */ short l_pid; /* returned with F_GETLK */The value of l_whence is 0, 1, or 2 to indicate that the relative offset, l_start bytes, is measured from the start of the file, current position, or end of file, respectively. The value of l_len is the number of consecutive bytes to be locked. The process id system call.
When mandatory file and record locking is active on a file (see chmod(S)), read and write system calls issued on the file are affected by the record locks in effect.
The fcntl system call fails if one or more of the following is true:
Otherwise, a value of -1 is returned, and errno is set to indicate the error.
X/Open Portability Guide, Issue 3, 1989
;
IEEE POSIX Std 1003.1-1990 System Application Program Interface (API) [C Language] (ISO/IEC 9945-1) ;
and NIST FIPS 151-1 .