Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
File descriptor
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Operations on file descriptors== The following lists typical operations on file descriptors on modern [[Unix-like]] systems. Most of these functions are declared in the <code><unistd.h></code> header, but some are in the <code><fcntl.h></code> header instead. ===Creating file descriptors=== *{{mono|[[open (system call)|open]]()}} *{{mono|creat()}}<!-- Not a typo --><ref>{{cite web |url=http://pubs.opengroup.org/onlinepubs/9699919799/functions/creat.html |title=The Open Group Base Specifications Issue 7, IEEE Std 1003.1-2008, 2018 Edition β creat |author=The Open Group |access-date=2019-04-11 |author-link=The Open Group }}</ref> *{{mono|socket()}} *{{mono|accept()}} *{{mono|socketpair()}} *{{mono|pipe()}} *{{mono|epoll_create()}} (Linux) *{{mono|signalfd()}} (Linux) *{{mono|eventfd()}} (Linux) *{{mono|timerfd_create()}} (Linux) *{{mono|memfd_create()}} (Linux) *{{mono|userfaultfd()}} (Linux) *{{mono|fanotify_init()}} (Linux) *{{mono|inotify_init()}} (Linux) *{{mono|clone()}} (with flag CLONE_PIDFD, Linux) *{{mono|pidfd_open()}} (Linux) *{{mono|open_by_handle_at()}} (Linux) *{{mono|kqueue()}} (BSD) *{{mono|pdfork()}} (kFreeBSD) ===Deriving file descriptors=== *{{mono|dirfd()}} *{{mono|fileno()}} ===Operations on a single file descriptor=== *{{mono|[[read (system call)|read]](), [[write (system call)|write]]()}} *{{mono|readv()}}, {{mono|writev()}} *{{mono|pread()}}, {{mono|pwrite()}} *{{mono|recv()}}, {{mono|send()}} *{{mono|recvfrom()}}, {{mono|sendto()}} *{{mono|recvmsg()}}, {{mono|sendmsg()}} (also used for sending FDs to other processes over a Unix domain socket) *{{mono|recvmmsg()}}, {{mono|sendmmsg()}} *{{mono|lseek()}}, {{mono|llseek()}} *{{mono|[[stat (system call)|fstat()]]}} *{{mono|fstatvfs()}} *{{mono|fchmod()}} *{{mono|fchown()}} *{{mono|ftruncate()}} *{{mono|fsync()}} *{{mono|fdatasync()}} *{{mono|fdopendir()}} *{{mono|fgetxattr()}}, {{mono|fsetxattr()}} (Linux) *{{mono|flistxattr()}}, {{mono|fremovexattr()}} (Linux) *{{mono|statx}} (Linux) *{{mono|setns}} (Linux) *{{mono|vmsplice()}} (Linux) *{{mono|pidfd_send_signal()}} (Linux) *{{mono|pdkill()}} (kFreeBSD) *{{mono|waitid()}} (with P_PIDFD ID type, Linux) *{{mono|fdopen()}} (stdio function:converts file descriptor to FILE*) *{{mono|dprintf()}} (stdio function: prints to file descriptor) ===Operations on multiple file descriptors=== *[[select (Unix)|{{mono|select()}}]], {{mono|pselect()}} *[[poll (Unix)|{{mono|poll()}}]], {{mono|ppoll()}} *{{mono|epoll_wait()}}, {{mono|epoll_pwait()}}, {{mono|epoll_pwait2()}} (Linux, takes a single epoll filedescriptor to wait on many other file descriptors) *[[Epoll|{{mono|epoll_ctl()}}]] (for Linux) *[[Kqueue|{{mono|kqueue()}}]] (for BSD-based systems). *{{mono|sendfile()}} *[[splice (system call)|{{mono|splice()}}]], {{mono|tee()}} (for Linux) *{{mono|copy_file_range()}} (for Linux) ===Operations on the file descriptor table=== The {{mono|fcntl()}} function is used to perform various operations on a file descriptor, depending on the command argument passed to it. There are commands to get and set attributes associated with a file descriptor, including {{mono|F_GETFD, F_SETFD, F_GETFL}} and {{mono|F_SETFL}}. *{{mono|[[close (system call)|close()]]}} *{{mono|closefrom()}} (BSD and Solaris only; deletes all file descriptors greater than or equal to specified number) *{{mono|close_range()}} (for Linux)<ref>{{cite web |url=https://man7.org/linux/man-pages/man2/close_range.2.html |title=close_range(2) β Linux manual page |author=Stephen Kitt, Michael Kerrisk |access-date=2021-03-22 }}</ref> *{{mono|[[dup (system call)|dup()]]}} (duplicates an existing file descriptor guaranteeing to be the lowest number available file descriptor) *{{mono|[[dup2]]()}}, {{mono|[[Dup2|dup3()]]}} (Close fd1 if necessary, and make file descriptor fd1 point to the open file of fd2) *{{mono|fcntl (F_DUPFD)}} ===Operations that modify process state=== *{{mono|fchdir()}} (sets the process's current working directory based on a directory file descriptor) *{{mono|[[mmap]]()}} (maps ranges of a file into the process's address space) ===File locking=== * {{mono|flock()}} * {{mono|fcntl() (F_GETLK, F_SETLK}} and {{mono|F_SETLKW)}} * {{mono|lockf()}} ===Sockets=== {{See also|Berkeley sockets}} *{{mono|connect()}} *{{mono|bind()}} *{{mono|listen()}} *{{mono|accept()}} (creates a new file descriptor for an incoming connection) *{{mono|getsockname()}} *{{mono|getpeername()}} *{{mono|getsockopt()}} *{{mono|setsockopt()}} *{{mono|shutdown()}} (shuts down one or both halves of a full duplex connection) ===Miscellaneous=== *[[ioctl|{{mono|ioctl()}}]] (a large collection of miscellaneous operations on a single file descriptor, often associated with a device)
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)