fcntl(2)

fcntl2

Manipulate file descriptor

Usage

#include <fcntl.h>

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

Library

Standard C library (libc, -lc)

Overview

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

File descriptor flags

File status flags

Advisory record locking

Open file description locks (non-POSIX)

Managing signals

Leases

Delegations

File and directory change notification (dnotify)

Changing the capacity of a pipe

File Sealing

File read/write hints

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.

Releases

19 releases since Debian 1.1 (Buzz); the text changed 17 times.

  1. 1.1–1.2
  2. 1.3
  3. 2.0
  4. 2.1
  5. 2.2
  6. 3.0
  7. 3.1
  8. 4.0
  9. 5.0
  10. 6.0
  11. 7
  12. 8
  13. 9
  14. 10
  15. 11
  16. 12
  17. 13
  18. Arch

Standards

POSIX.1-2024.

History

4.3BSD, SVr4, POSIX.1-1988.

From man-pages 6.19-1 in Arch Linux 2026-11-01. Parsed by carta from the page's man source.