FD(4)
π FD(4) π
okay bestie, we're doing the file descriptor files page from the Kernel Interfaces Manual, and honestly? it's giving β¨the filesystem is a lie but a useful oneβ¨
β¨ NAME β¨
fd, stdin, stdout, stderr β file descriptor files π
like. literally the files that ARE your file descriptors. the way that's so iconic of them.
πΈ DESCRIPTION πΈ
okay so. the files /dev/fd/0 through /dev/fd/# refer to file descriptors that you can access through the file system. yes queen, your fds are just... files now. we love a crossover episode π
so here's the tea π β if the file descriptor is open, and the mode the file is being opened with is a subset of the mode of the existing descriptor, then this call:
fd = open("/dev/fd/0", mode);
and this call:
fd = fcntl(0, F_DUPFD, 0);
are equivalent. same vibe, same result, no cap. π₯
and opening /dev/stdin, /dev/stdout and /dev/stderr? that's equivalent to these three calls right here:
fd = fcntl(STDIN_FILENO, F_DUPFD, 0);
fd = fcntl(STDOUT_FILENO, F_DUPFD, 0);
fd = fcntl(STDERR_FILENO, F_DUPFD, 0);
so cute. so consistent. π¦
β οΈ okay important bestie: flags to theopen(2)call other thanO_RDONLY,O_WRONLYandO_RDWRare ignored. like, straight up not read. don't be out here expecting them to do something, because they will not, and that's just how it is. π
π§ IMPLEMENTATION NOTES π§
so by default, /dev/fd is provided by devfs(5), which provides nodes for the first three file descriptors. that's your main character trio right there, we stan. π
some sites may require nodes for additional file descriptors though β and those can be made available by mounting fdescfs(5) on /dev/fd. so if you need more than three, that's the move. slay. π
π FILES π
/dev/fd/#/dev/stdin/dev/stdout/dev/stderr
the whole squad, assembled. π«Ά
β SEE ALSO β
go read those next bestie, they're part of the lore π
okay so that's the whole page!! shoutout to the Debian girlies for shipping this one way back on June 9, 1993 β literally older than all of us and still lowkey essential. periodt πβ¨π
π¦ where this page comes from
- debian bookworm: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- Copyright (c) 1990, 1991, 1993 The Regents of the University of California. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms