---
name: "F_DUPFD"
section: "2const"
platform: "linux"
package: "man-pages"
version: "6.19-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/F_DUPFD"
---

# F\_DUPFD(2const)

duplicate a file descriptor

## NAME

F\_DUPFD, F\_DUPFD\_CLOEXEC - duplicate a file descriptor

## LIBRARY

Standard C library (*libc*, *-lc*)

## SYNOPSIS

```
#include <fcntl.h>
```

**int fcntl(int** *fd***, F\_DUPFD, int** *arg***);** **int fcntl(int** *fd***, F\_DUPFD\_CLOEXEC, int** *arg***);**

## DESCRIPTION

- **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)](/dup2/2.md), which uses exactly the file descriptor specified.

-

  On success, the new file descriptor is returned.

-

  See [**dup**(2)](/dup/2.md) 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)](/F_SETFD/2const.md) 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)](/open/2.md).

## RETURN VALUE

The new file descriptor.

On error, -1 is returned, and *errno* is set to indicate the error.

## ERRORS

See [**fcntl**(2)](/fcntl/2.md).

- **EINVAL**

  *arg* is negative or is greater than the maximum allowable value (see the discussion of **RLIMIT\_NOFILE** in [**getrlimit**(2)](/getrlimit/2.md)).

- **EMFILE**

  The per-process limit on the number of open file descriptors has been reached.

## VERSIONS

POSIX.1-2024 specifies **F\_DUPFD\_CLOFORK**, but Linux doesn't support it.

## STANDARDS

POSIX.1-2024.

## HISTORY

- **F\_DUPFD**

  SVr4, 4.3BSD, POSIX.1-1988.

- **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.)

## CAVEATS

The errors returned by [**dup2**(2)](/dup2/2.md) are different from those returned by **F\_DUPFD**.

## SEE ALSO

[**dup2**(2)](/dup2/2.md), [**fcntl**(2)](/fcntl/2.md)
