FCNTL (2)
manipulate file descriptor
SYNOPSIS
#include <unistd.h>
#include <fcntl.h>
int fcntl(int fd , int cmd );
int fcntl(int fd , int cmd , long arg );
int fcntl(int fd , int cmd , struct flock * lock );
DESCRIPTION
fcntl
performs one of various miscellaneous operations on
fd .
The operation in question is determined by
cmd :
F_DUPFD
Find the lowest numbered availiable file descriptor
greater than or equal to
arg
and make it be a copy of
fd .
This is different form
dup2 (2)
which uses exactly the descriptor specified.
The old and new descriptors may be used interchangeably. They share locks,
file position pointers and flags; for example, if the file position is
modified by using
lseek
on one of the descriptors, the position is also changed for the other.
The two descriptors do not share the close-on-exec flag, however.
The close-on-exec flag of the copy is off, meaning that it will
not be closed on exec.
On success, the new descriptor is returned.
F_GETFD
Read the close-on-exec flag. If the
FD_CLOEXEC
bit is 0, the file will remain open across
exec ,
otherwise it will be closed.
F_SETFD
Set the close-on-exec flag to the value specified by the
FD_CLOEXEC
bit of
arg .
F_GETFL
Read the descriptor's flags (all flags (as set by
open (2))
are returned).
F_SETFL
Set the descriptor's flags to the value specified by
arg .
Only
O_APPEND , O_NONBLOCK and O_ASYNC
may be set; the other flags are unaffected.
The flags are shared between copies (made with
dup (2), fork (2),
etc.) of the same file descriptor.
The flags and their semantics are described in
open (2).
F_GETLK , F_SETLK and F_SETLKW
are used to manage discretionary file locks.
The third argument
lock
is a pointer to a struct flock
(that may be overwritten by this call).
F_GETLK
Return the flock structure that prevents us from obtaining
the lock, or set the
l_type
field of the lock to
F_UNLCK
if there is no obstruction.
F_SETLK
The lock is set (when
l_type
is
F_RDLCK
or
F_WRLCK )
or cleared (when it is
F_UNLCK ).
If the lock is held by someone
else, this call returns -1 and sets
errno
to
EACCES
or
EAGAIN .
F_SETLKW
Like
F_SETLK ,
but instead of returning an error we wait for the lock to be released.
If a signal that is to be caught is received while
fcntl
is waiting, it is interrupted and (after the signal handler has returned)
returns immediately (with return value -1 and
errno
set to
EINTR ).
F_GETOWN , F_SETOWN , F_GETSIG and F_SETSIG
are used to manage I/O availability signals:
F_GETOWN
Get the process ID or process group currently receiving SIGIO
and SIGURG signals for events on file descriptor
fd .
Process groups are returned as negative values.
F_SETOWN
Set the process ID or process group that will receive SIGIO
and SIGURG signals for events on file descriptor
fd .
Process groups are specified using negative values.
( F_SETSIG
can be used to specify a different signal instead of SIGIO).
|