lockf(3) Library Functions Manual lockf(3) lockf - , POSIX C (libc, -lc) #include int lockf(int fd, int op, off_t len); glibc (. feature_test_macros(7)): lockf(): _XOPEN_SOURCE >= 500 || /* glibc >= 2.19: */ _DEFAULT_SOURCE || /* glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE Apply, test, or remove a POSIX lock on a section of an open file. The file is specified by fd, a file descriptor open for writing, the action by op, and the section consists of byte positions pos..pos+len-1 if len is positive, and pos-len..pos-1 if len is negative, where pos is the current file position, and if len is zero, the section extends from the current file position to infinity, encompassing the present and future end-of-file positions. In all cases, the section may extend past current end-of-file. Linux lockf() -- fcntl(2) . lockf() , , POSIX.1 lockf() fcntl(2). , , . : F_LOCK . ( ) , , . , . , . . F_TLOCK , F_LOCK, , . F_ULOCK . , . F_TEST : 0, ; -1, errno EAGAIN ( EACCES), . 0. -1, errno . EACCES EAGAIN F_TLOCK F_TEST, , . EBADF fd is not an open file descriptor; or op is F_LOCK or F_TLOCK and fd is not a writable file descriptor. EDEADLK op was F_LOCK and this lock operation would cause a deadlock. EINTR , ; signal(7). EINVAL An invalid operation was specified in op. ENOLCK , . attributes(7). +----------------------------+----------------------------------------------------------+--------------------------+ | | | | +----------------------------+----------------------------------------------------------+--------------------------+ |lockf() | | MT-Safe | +----------------------------+----------------------------------------------------------+--------------------------+ POSIX.1-2008. POSIX.1-2001, SVr4. fcntl(2), flock(2) locks.txt mandatory-locking.txt Documentation/filesystems Linux ( Documentation, mandatory-locking.txt mandatory.txt). () Artyom Kunyov , Azamat Hackimov , Dmitry Bolkhovskikh , Katrin Kutepova , Konstantin Shvaykovskiy , Yuri Kozlov ; GNU (GNU General Public License - GPL, 3 ) , - . - , , () () () <>. Linux 6.9.1 2 2024 . lockf(3)