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

# fcntl(2)

manipulate file descriptor

## NAME

fcntl - manipulate file descriptor

## LIBRARY

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

## SYNOPSIS

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

**int fcntl(int** *fd***, int** *op***, ...);**

## DESCRIPTION

**fcntl**() performs one of the operations described below on the open file descriptor *fd*. The operation is determined by *op*.

Certain of the operations below are supported only since a particular Linux kernel version. The preferred method of checking whether the host kernel supports a particular operation is to invoke **fcntl**() with the desired *op* value and then test whether the call failed with **EINVAL**, indicating that the kernel does not recognize this value.

### Duplicating a file descriptor

- [**F\_DUPFD**(2const)](/F_DUPFD/2const.md) [**F\_DUPFD\_CLOEXEC**(2const)](/F_DUPFD_CLOEXEC/2const.md)

  ### File descriptor flags

- [**F\_GETFD**(2const)](/F_GETFD/2const.md) [**F\_SETFD**(2const)](/F_SETFD/2const.md)

  ### File status flags

- [**F\_GETFL**(2const)](/F_GETFL/2const.md) [**F\_SETFL**(2const)](/F_SETFL/2const.md)

  ### Advisory record locking

- [**F\_SETLK**(2const)](/F_SETLK/2const.md) [**F\_SETLKW**(2const)](/F_SETLKW/2const.md) [**F\_GETLK**(2const)](/F_GETLK/2const.md)

  ### Open file description locks (non-POSIX)

- [**F\_OFD\_SETLK**(2const)](/F_OFD_SETLK/2const.md) [**F\_OFD\_SETLKW**(2const)](/F_OFD_SETLKW/2const.md) [**F\_OFD\_GETLK**(2const)](/F_OFD_GETLK/2const.md)

  ### Managing signals

- [**F\_GETOWN**(2const)](/F_GETOWN/2const.md) [**F\_SETOWN**(2const)](/F_SETOWN/2const.md) [**F\_GETOWN\_EX**(2const)](/F_GETOWN_EX/2const.md) [**F\_SETOWN\_EX**(2const)](/F_SETOWN_EX/2const.md) [**F\_GETSIG**(2const)](/F_GETSIG/2const.md) [**F\_SETSIG**(2const)](/F_SETSIG/2const.md)

  ### Leases

- [**F\_SETLEASE**(2const)](/F_SETLEASE/2const.md) [**F\_GETLEASE**(2const)](/F_GETLEASE/2const.md)

  ### Delegations

- [**F\_SETDELEG**(2const)](/F_SETDELEG/2const.md) [**F\_GETDELEG**(2const)](/F_GETDELEG/2const.md)

  ### File and directory change notification (dnotify)

- [**F\_NOTIFY**(2const)](/F_NOTIFY/2const.md)

  ### Changing the capacity of a pipe

- [**F\_SETPIPE\_SZ**(2const)](/F_SETPIPE_SZ/2const.md) [**F\_GETPIPE\_SZ**(2const)](/F_GETPIPE_SZ/2const.md)

  ### File Sealing

- [**F\_ADD\_SEALS**(2const)](/F_ADD_SEALS/2const.md) [**F\_GET\_SEALS**(2const)](/F_GET_SEALS/2const.md)

  ### File read/write hints

- [**F\_GET\_RW\_HINT**(2const)](/F_GET_RW_HINT/2const.md) [**F\_SET\_RW\_HINT**(2const)](/F_SET_RW_HINT/2const.md) [**F\_GET\_FILE\_RW\_HINT**(2const)](/F_GET_FILE_RW_HINT/2const.md) [**F\_SET\_FILE\_RW\_HINT**(2const)](/F_SET_FILE_RW_HINT/2const.md)

  ## RETURN VALUE

For a successful call, the return value depends on the operation.

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

## ERRORS

- **EACCES** or **EAGAIN**

  Operation is prohibited by locks held by other processes.

- **EAGAIN**

  The operation is prohibited because the file has been memory-mapped by another process.

- **EBADF**

  *fd* is not an open file descriptor

- **EINVAL**

  The value specified in *op* is not recognized by this kernel.

## VERSIONS

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

## STANDARDS

POSIX.1-2024.

## HISTORY

4\.3BSD, SVr4, POSIX.1-1988.

## SEE ALSO

[**dup2**(2)](/dup2/2.md), [**flock**(2)](/flock/2.md), [**open**(2)](/open/2.md), [**socket**(2)](/socket/2.md), [**lockf**(3)](/lockf/3.md), [**capabilities**(7)](/capabilities/7.md), [**feature\_test\_macros**(7)](/feature_test_macros/7.md), [**lslocks**(8)](/lslocks/8.md)
