fcntl(2)
๐ fcntl โ manipulate file descriptor
okay bestie, pull up a chair ๐ this is <fcntl.h>, the header you include before you get to play. and yes, the manual calls this thing fcntl(2) โ a system call, not a library page, so jot that down. it lives in the Standard C library (libc, link with -lc). we're doing file descriptor manipulation today and honestly? she ate. ๐ฅ
โจ SYNOPSIS โจ
#include <fcntl.h>
int fcntl(int fd, int op, ...);
๐ธ DESCRIPTION ๐ธ
so <pink>fcntl()does **one of the operations described below** on the open file descriptorfd. which one? that's literally what opis for, bestie.op` picks the operation. periodt. ๐
now real talk โ some of these operations only exist since a particular Linux kernel version. and the preferred way to check whether your host kernel even supports a particular operation? you just call fcntl() with the op value you want, and then test whether the call failed with EINVAL โ because EINVAL means the kernel doesn't recognize this value. that's the vibe check. ๐ซถ
๐ฆ Duplicating a file descriptor
๐ฆ File descriptor flags
๐ฆ File status flags
๐ฆ Advisory record locking
๐ฆ Open file description locks (non-POSIX)
๐ฆ Managing signals
F_GETOWN(2const)F_SETOWN(2const)F_GETOWN_EX(2const)F_SETOWN_EX(2const)F_GETSIG(2const)F_SETSIG(2const)
๐ฆ Leases
๐ฆ Delegations
๐ฆ File and directory change notification (dnotify)
๐ฆ Changing the capacity of a pipe
๐ฆ File Sealing
๐ฆ File read/write hints
๐ RETURN VALUE ๐
good news: on success, the return value depends on the operation. it's giving โจsituationalโจ. no single answer, sorry bestie.
bad news: on error, -1 is returned, and errno is set to indicate the error. ๐ญ
๐ ERRORS ๐
EACCESorEAGAINโ Operation is prohibited by locks held by other processes. somebody else is holding the lock, and it is not your turn. ๐EAGAINโ The operation is prohibited because the file has been memory-mapped by another process.EBADFโfdis not an open file descriptor. ma'am. that's not a real fd. ๐EINVALโ The value specified inopis not recognized by this kernel.
๐ VERSIONS ๐
POSIX.1-2024 specifies FD_CLOFORK and F_DUPFD_CLOFORK, but Linux doesn't support them. not us, not our house, we don't have those. ๐
โ๏ธ
โญ STANDARDS โญ
POSIX.1-2024. iykyk. ๐
๐ HISTORY ๐
4.3BSD, SVr4, POSIX.1-1988. she's got lore. she's been around. iconic behavior honestly. ๐ซถ
๐ SEE ALSO ๐
ok that's the whole page bestie, all 40-ish of those F_* operations, every flag, every error, every standard, nothing skipped, no cap. go forth and manipulate some file descriptors responsibly. ๐ธ๐
and before you go โ this lil masterpiece is from the Linux man-pages 6.20, dated 2026-02-08. slay. โจ
๐ฆ where this page comes from
- arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- ๐ the page's license: Linux-man-pages-copyleft
- Copyright 1992, Drew Eckhardt <drew@cs.colorado.edu>
- Copyright 1992, Ian Jackson <iwj10@cus.cam.ac.uk>
- Copyright 1998, Jamie Lokier <jamie@imbolc.ucc.ie>
- Copyright 2002-2012, Michael Kerrisk <mtk.manpages@gmail.com>
- Copyright 2014, Jeff Layton <jlayton@kernel.org>
- Copyright 2014, David Herrmann <dh.herrmann@gmail.com>
- Copyright 2017, Jens Axboe <axboe@kernel.dk>
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms