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(intfd, F_DUPFD, intarg);int fcntl(intfd, F_DUPFD_CLOEXEC, intarg);
F_DUPFD Duplicate the file descriptorfd using the lowest-numbered available file descriptor greater than or equal toarg. This is different fromdup2(2), which uses exactly the file descriptor specified. On success, the new file descriptor is returned. Seedup(2) for further details.F_DUPFD_CLOEXEC As forF_DUPFD, but additionally set the close-on-exec flag for the duplicate file descriptor. Specifying this flag permits a program to avoid an additionalF_SETFD(2const) operation to set theFD_CLOEXECflag. For an explanation of why this flag is useful, see the description ofO_CLOEXECinopen(2).
The new file descriptor. On error, -1 is returned, anderrno is set to indicate the error.
Seefcntl(2).EINVALarg is negative or is greater than the maximum allowable value (see the discussion ofRLIMIT_NOFILEingetrlimit(2)).EMFILEThe per-process limit on the number of open file descriptors has been reached.
POSIX.1-2024 specifiesF_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_SOURCEwith the value 200809L or greater, or_XOPEN_SOURCEwith the value 700 or greater.)
The errors returned bydup2(2) are different from those returned byF_DUPFD.
dup2(2),fcntl(2)
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-19F_DUPFD(2const)Pages that refer to this page:fcntl(2), fcntl_locking(2), F_GETFL(2const)
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. | ![]() |