fcntl − manipulate file descriptor
Standard C library (libc, −lc)
#include <fcntl.h>
int fcntl(int fd, int op, ...);
fcntl() performs one of the operations described below on the open file descriptor fd. The operation is determined by op.
Certain of the operations below are supported only since a particular Linux kernel version. The preferred method of checking whether the host kernel supports a particular operation is to invoke fcntl() with the desired op value and then test whether the call failed with EINVAL, indicating that the kernel does not recognize this value.
F_DUPFD(2const)
F_DUPFD_CLOEXEC(2const)
F_GETFD(2const)
F_SETFD(2const)
F_GETFL(2const)
F_SETFL(2const)
F_SETLK(2const)
F_SETLKW(2const)
F_GETLK(2const)
F_OFD_SETLK(2const)
F_OFD_SETLKW(2const)
F_OFD_GETLK(2const)
F_GETOWN(2const)
F_SETOWN(2const)
F_GETOWN_EX(2const)
F_SETOWN_EX(2const)
F_GETSIG(2const)
F_SETSIG(2const)
F_SETLEASE(2const)
F_GETLEASE(2const)
F_NOTIFY(2const)
F_SETPIPE_SZ(2const)
F_GETPIPE_SZ(2const)
F_ADD_SEALS(2const)
F_GET_SEALS(2const)
F_GET_RW_HINT(2const)
F_SET_RW_HINT(2const)
F_GET_FILE_RW_HINT(2const)
F_SET_FILE_RW_HINT(2const)
For a successful call, the return value depends on the operation.
On error, −1 is returned, and errno is set to indicate the error.
EACCES or EAGAIN
Operation is prohibited by locks held by other processes.
|
EAGAIN |
The operation is prohibited because the file has been memory-mapped by another process. | ||
|
EBADF |
fd is not an open file descriptor | ||
|
EINVAL |
The value specified in op is not recognized by this kernel. |
POSIX.1-2024 specifies FD_CLOFORK and F_DUPFD_CLOFORK, but Linux doesn’t support them.
POSIX.1-2024.
SVr4, 4.3BSD, POSIX.1-2001.
dup2(2), flock(2), open(2), socket(2), lockf(3), capabilities(7), feature_test_macros(7), lslocks(8)