#include <sys/types.h> #include <fcntl.h> #include <unistd.h> int fcntl( int fildes, int cmd );
fcntl
with function F_SETLKW would cause a deadlock.
fcntl()
performs one of various miscellaneous operations on
fd
. The operation in question is determined by cmd
:
arg
be a copy of fd
, closing fd
first if necessary.
The same functionality can be more easily achieved by using dup2()
.
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 be closed on exec.
On success, the new descriptor is returned.
arg
(only the least
significant bit is used).
arg
. Only
O_APPEND
and O_NONBLOCK
may be set.
The flags are shared between copies (made with dup()
etc.) of the same
file descriptor.
The flags and their semantics are described in open()
.
arg
is a pointer to a
struct flock (that may be overwritten by this call).
l_type
field of the lock to F_UNLCK
if there is no obstruction.
l_type
is F_RDLCK
or F_WRLCK
) or
cleared (when it is F_UNLCK
. If lock is held by someone else, this
call returns -1 and sets errno
to EACCES or EAGAIN.
F_SETLK
, but instead of returning an error we wait for the lock to
be released.
Process groups are returned as negative values.
For these commands, ownership means receiving SIGIO
or SIGURG
signals.
Process groups are specified using negative values.
The errors returned by dup2
are different from those returned by
F_DUPFD
.
Copyright © 1988-2000 OAR Corporation