This section describes how you can perform various other operations on
file descriptors, such as inquiring about or setting flags describing
the status of the file descriptor, manipulating record locks, and the
like. All of these operations are performed by the function
The second argument to the
fcntl function is a command that
specifies which operation to perform. The function and macros that name
various flags that are used with it are declared in the header file
fcntl.h. Many of these flags are also used by the
function; see Opening and Closing Files.
Preliminary: | MT-Safe | AS-Safe | AC-Safe | See POSIX Safety Concepts.
fcntl function performs the operation specified by
command on the file descriptor filedes. Some commands
require additional arguments to be supplied. These additional arguments
and the return value and error conditions are given in the detailed
descriptions of the individual commands.
Briefly, here is a list of what the various commands are.
Duplicate the file descriptor (return another file descriptor pointing to the same open file). See Duplicating Descriptors.
Get flags associated with the file descriptor. See Descriptor Flags.
Set flags associated with the file descriptor. See Descriptor Flags.
Get flags associated with the open file. See File Status Flags.
Set flags associated with the open file. See File Status Flags.
Test a file lock. See File Locks.
Set or clear a file lock. See File Locks.
F_SETLK, but wait for completion. See File Locks.
Test an open file description lock. See Open File Description Locks. Specific to Linux.
Set or clear an open file description lock. See Open File Description Locks. Specific to Linux.
F_OFD_SETLK, but block until lock is acquired.
See Open File Description Locks. Specific to Linux.
Get process or process group ID to receive
See Interrupt Input.
Set process or process group ID to receive
See Interrupt Input.
This function is a cancellation point in multi-threaded programs for the
F_SETLKW (and the LFS analogous
F_OFD_SETLKW. This is a problem if the thread allocates some
resources (like memory, file descriptors, semaphores or whatever) at the time
fcntl is called. If the thread gets canceled these resources stay
allocated until the program ends. To avoid this calls to
be protected using cancellation handlers.