|
NAMElockf —
record locking on files
LIBRARYStandard C Library (libc, -lc)SYNOPSIS#include <unistd.h>
int
DESCRIPTIONThelockf () function allows sections of a file to be
locked with advisory-mode locks. Calls to lockf () from
other processes which attempt to lock the locked file section will either
return an error value or block until the section becomes unlocked. All the
locks for a process are removed when the process terminates.
The argument fd is an open file descriptor.
The file descriptor must have been opened either for write-only
( The function argument is a control value which specifies the action to be taken. The permissible values for function are as follows:
The size argument is the number of contiguous bytes to be locked or unlocked. The section to be locked or unlocked starts at the current offset in the file and extends forward for a positive size or backward for a negative size (the preceding bytes up to but not including the current offset). However, it is not permitted to lock a section that starts or extends before the beginning of the file. If size is 0, the section from the current offset through the largest possible file offset is locked (that is, from the current offset through the present or any future end-of-file). The sections locked with
File locks are released on first close by the locking process of any file descriptor for the file.
An A potential for deadlock occurs if a process controlling a locked
region is put to sleep by attempting to lock the locked region of another
process. This implementation detects that sleeping until a locked region is
unlocked would cause a deadlock and fails with an
The Blocking on a section is interrupted by any signal. RETURN VALUESThelockf () function returns the value 0 if
successful; otherwise the value -1 is returned and the global variable
errno is set to indicate the error. In the case of a
failure, existing locks are not changed.
ERRORSThelockf () function will fail if:
SEE ALSOfcntl(2), flock(2)STANDARDSThelockf () function conforms to X/Open
Portability Guide Issue 4, Version 2
(“XPG4.2”).
Visit the GSP FreeBSD Man Page Interface. |