NAME |LIBRARY |SYNOPSIS |DESCRIPTION |RETURN VALUE |ERRORS |VERSIONS |STANDARDS |HISTORY |SEE ALSO |COLOPHON | |
fcntl(2) System Calls Manualfcntl(2)fcntl - manipulate file descriptor
Standard C library (libc,-lc)
#include <fcntl.h>int fcntl(intfd, intop, ...);
fcntl() performs one of the operations described below on the open file descriptorfd. The operation is determined byop. 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 invokefcntl() with the desiredop value and then test whether the call failed withEINVAL, indicating that the kernel does not recognize this value.Duplicating a file descriptorF_DUPFD(2const)F_DUPFD_CLOEXEC(2const)File descriptor flagsF_GETFD(2const)F_SETFD(2const)File status flagsF_GETFL(2const)F_SETFL(2const)Advisory record lockingF_SETLK(2const)F_SETLKW(2const)F_GETLK(2const)Open file description locks (non-POSIX)F_OFD_SETLK(2const)F_OFD_SETLKW(2const)F_OFD_GETLK(2const)Managing signalsF_GETOWN(2const)F_SETOWN(2const)F_GETOWN_EX(2const)F_SETOWN_EX(2const)F_GETSIG(2const)F_SETSIG(2const)LeasesF_SETLEASE(2const)F_GETLEASE(2const)File and directory change notification (dnotify)F_NOTIFY(2const)Changing the capacity of a pipeF_SETPIPE_SZ(2const)F_GETPIPE_SZ(2const)File SealingF_ADD_SEALS(2const)F_GET_SEALS(2const)File read/write hintsF_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, anderrno is set to indicate the error.
EACCESorEAGAIN Operation is prohibited by locks held by other processes.EAGAINThe operation is prohibited because the file has been memory-mapped by another process.EBADFfd is not an open file descriptorEINVALThe value specified inop is not recognized by this kernel.
POSIX.1-2024 specifiesFD_CLOFORKandF_DUPFD_CLOFORK, but Linux doesn't support them.
POSIX.1-2008.
SVr4, 4.3BSD, POSIX.1-2001.
dup2(2),flock(2),open(2),socket(2),lockf(3),capabilities(7),feature_test_macros(7),lslocks(8)
This page is part of theman-pages (Linux kernel and C library user-space interface documentation) project. Information about the project can be found at ⟨https://www.kernel.org/doc/man-pages/⟩. If you have a bug report for this manual page, see ⟨https://git.kernel.org/pub/scm/docs/man-pages/man-pages.git/tree/CONTRIBUTING⟩. This page was obtained from the tarball man-pages-6.15.tar.gz fetched from ⟨https://mirrors.edge.kernel.org/pub/linux/docs/man-pages/⟩ on 2025-08-11. If you discover any rendering problems in this HTML version of the page, or you believe there is a better or more up- to-date source for the page, or you have corrections or improvements to the information in this COLOPHON (which isnot part of the original manual page), send a mail to man-pages@man7.orgLinux man-pages 6.15 2025-07-20fcntl(2)Pages that refer to this page:flock(1), pipesz(1), accept(2), bpf(2), chmod(2), clone(2), close(2), dup(2), eventfd(2), execve(2), fallocate(2), fcntl_locking(2), F_DUPFD(2const), F_GETFD(2const), F_GETFL(2const), F_GETLEASE(2const), F_GETPIPE_SZ(2const), F_GET_RW_HINT(2const), F_GET_SEALS(2const), F_GETSIG(2const), flock(2), F_NOTIFY(2const), fork(2), getrlimit(2), gettid(2), inotify_init(2), ioctl(2), ioctl_console(2), memfd_create(2), memfd_secret(2), mknod(2), mmap(2), mount(2), NS_GET_USERNS(2const), open(2), perf_event_open(2), pidfd_getfd(2), pipe(2), read(2), recv(2), select_tut(2), send(2), sigaction(2), signalfd(2), socket(2), statfs(2), syscalls(2), timerfd_create(2), truncate(2), userfaultfd(2), write(2), audit_open(3), dbopen(3), fopen(3), lockf(3), sd_event_add_io(3), shm_open(3), sockatmark(3), statvfs(3), nfs(5), proc_locks(5), proc_sys_fs(5), systemd.socket(5), capabilities(7), credentials(7), epoll(7), inotify(7), landlock(7), man-pages(7), pipe(7), pthreads(7), signal(7), signal-safety(7), socket(7), tcp(7), lslocks(8), mount(8)
HTML rendering created 2025-09-06 byMichael Kerrisk, author ofThe Linux Programming Interface. For details of in-depthLinux/UNIX system programming training courses that I teach, lookhere. Hosting byjambit GmbH. | ![]() |