Scroll to navigation

fcntl(2) System Calls Manual fcntl(2)

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

File descriptor flags

File status flags

Advisory record locking

Open file description locks (non-POSIX)

Managing signals

Leases

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

Operation is prohibited by locks held by other processes.
The operation is prohibited because the file has been memory-mapped by another process.
fd is not an open file descriptor
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-2008.

HISTORY

SVr4, 4.3BSD, POSIX.1-2001.

SEE ALSO

dup2(2), flock(2), open(2), socket(2), lockf(3), capabilities(7), feature_test_macros(7), lslocks(8)

2025-07-20 Linux man-pages (unreleased)