1LOCKF(3)                   Linux Programmer's Manual                  LOCKF(3)
2
3
4

NAME

6       lockf - apply, test or remove a POSIX lock on an open file
7

SYNOPSIS

9       #include <unistd.h>
10
11       int lockf(int fd, int cmd, off_t len);
12

DESCRIPTION

14       Apply,  test  or remove a POSIX lock on a section of an open file.  The
15       file is specified by fd, a file descriptor open for writing, the action
16       by  cmd,  and  the section consists of byte positions pos..pos+len-1 if
17       len is positive, and pos-len..pos-1 if len is negative,  where  pos  is
18       the current file position, and if len is zero, the section extends from
19       the current file position to infinity,  encompassing  the  present  and
20       future  end-of-file  positions.   In  all cases, the section may extend
21       past current end-of-file.
22
23       On Linux, this call is just an interface for  fcntl(2).   (In  general,
24       the relation between lockf() and fcntl() is unspecified.)
25
26       Valid operations are given below:
27
28       F_LOCK Set  an exclusive lock on the specified section of the file.  If
29              (part of) this section is already locked, the call blocks  until
30              the previous lock is released.  If this section overlaps an ear‐
31              lier locked section, both are merged.  File locks  are  released
32              as  soon  as  the  process  holding  the  locks closes some file
33              descriptor for the file. A child process does not inherit  these
34              locks.
35
36       F_TLOCK
37              Same  as  F_LOCK  but the call never blocks and returns an error
38              instead if the file is already locked.
39
40       F_ULOCK
41              Unlock the indicated section of the  file.   This  may  cause  a
42              locked section to be split into two locked sections.
43
44       F_TEST Test  the lock: return 0 if the specified section is unlocked or
45              locked by this process; return -1, set errno to  EAGAIN  (EACCES
46              on some other systems), if another process holds a lock.
47

RETURN VALUE

49       On  success,  zero is returned.  On error, -1 is returned, and errno is
50       set appropriately.
51

ERRORS

53       EACCES or EAGAIN
54              The file is locked and F_TLOCK or F_TEST was specified,  or  the
55              operation  is prohibited because the file has been memory-mapped
56              by another process.
57
58       EBADF  fd is not an open file descriptor.
59
60       EDEADLK
61              The command was T_LOCK and this lock  operation  would  cause  a
62              deadlock.
63
64       EINVAL An invalid operation was specified in fd.
65
66       ENOLCK Too many segment locks open, lock table is full.
67

CONFORMING TO

69       SVr4, POSIX.1-2001
70

SEE ALSO

72       fcntl(2), flock(2)
73       There are also locks.txt and mandatory.txt in /usr/src/linux/Documenta‐
74       tion.
75
76
77
78Linux 2.0                         2002-04-22                          LOCKF(3)
Impressum