lockf(3) Library Functions Manual lockf(3) lockf - , POSIX LIBRARY Standard C library (libc, -lc) #include int lockf(int fd, int cmd, 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 cmd, 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), . On success, zero is returned. On error, -1 is returned, and errno is set to indicate the error. EACCES EAGAIN F_TLOCK F_TEST, , . EBADF fd , cmd F_LOCK F_TLOCK fd . EDEADLK F_LOCK, (deadlock). EINTR , ; signal(7). EINVAL cmd . 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 3 , . . , , . Linux man-pages 6.06 31 2023 . lockf(3)