NAME | LIBRARY | SYNOPSIS | DESCRIPTION | RETURN VALUE | ERRORS | VERSIONS | STANDARDS | HISTORY | CAVEATS | SEE ALSO | COLOPHON |
|
|
F_DUPFD(2const) F_DUPFD(2const)
F_DUPFD, F_DUPFD_CLOEXEC - duplicate a file descriptor
Standard C library (libc, -lc)
#include <fcntl.h> int fcntl(int fd, F_DUPFD, int arg); int fcntl(int fd, F_DUPFD_CLOEXEC, int arg);
F_DUPFD Duplicate the file descriptor fd using the lowest-numbered available file descriptor greater than or equal to arg. This is different from dup2(2), which uses exactly the file descriptor specified. On success, the new file descriptor is returned. See dup(2) for further details. F_DUPFD_CLOEXEC As for F_DUPFD, but additionally set the close-on-exec flag for the duplicate file descriptor. Specifying this flag permits a program to avoid an additional F_SETFD(2const) operation to set the FD_CLOEXEC flag. For an explanation of why this flag is useful, see the description of O_CLOEXEC in open(2).
The new file descriptor. On error, -1 is returned, and errno is set to indicate the error.
See fcntl(2). EINVAL arg is negative or is greater than the maximum allowable value (see the discussion of RLIMIT_NOFILE in getrlimit(2)). EMFILE The per-process limit on the number of open file descriptors has been reached.
POSIX.1-2024 specifies F_DUPFD_CLOFORK, but Linux doesn't support it.
POSIX.1-2008.
F_DUPFD SVr4, 4.3BSD, POSIX.1-2001. F_DUPFD_CLOEXEC Linux 2.6.24. POSIX.1-2008. (To get this definition, define _POSIX_C_SOURCE with the value 200809L or greater, or _XOPEN_SOURCE with the value 700 or greater.)
The errors returned by dup2(2) are different from those returned by F_DUPFD.
dup2(2), fcntl(2)
This page is part of the man-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 is not
part of the original manual page), send a mail to
man-pages@man7.org
Linux man-pages 6.15 2025-07-19 F_DUPFD(2const)
Pages that refer to this page: fcntl(2), fcntl_locking(2), F_GETFL(2const)