fcntl.2 (2011 03)

f
fcntl(2) fcntl(2)
NAME
fcntl() - file control
SYNOPSIS
#include <fcntl.h>
int fcntl(int fildes, int cmd, ... /* arg */);
Remarks
The ANSI C ", ..." construct denotes a variable length argument list whose optional [or required]
members are given in the associated comment (
/* */).
DESCRIPTION
fcntl() provides for control over open files. fildes is an open file descriptor.
The following are possible values for the cmd argument:
F_ADVISE Fadvise service request (see fadvise (2)).
F_DUPFD Return a new file descriptor having the following characteristics:
Lowest numbered available file descriptor greater than or equal to the third
argument, arg , taken as an integer of type
int.
Same open file (or pipe) as the original file.
Same file pointer as the original file (that is, both file descriptors share one file
pointer).
Same access mode (read, write or read/write).
Same file status flags (that is, both file descriptors share the same file status
flags).
The close-on-exec flag associated with the new file descriptor is set to remain
open across
exec() system calls.
F_GETFD Get the file descriptor flags (defined in <fcntl.h>) that are associated with the
file descriptor fildes . File descriptor flags are associated with a single file descriptor
and do not affect other file descriptors that refer to the same file.
F_SETFD Set the file descriptor flags (defined in <fcntl.h>) that are associated with fildes ,
to the third argument, arg , taken as an integer of type
int (see F_GETFD). If the
FD_CLOEXEC flag in the third argument is 0, the file will remain open across
exec(); otherwise, the file will be closed upon execution of exec().
F_CLOSEM Close all open file descriptors greater than or equal to fildes .
F_GETFL Get file status flags and access modes; see fcntl (5).
F_SETFL Set file status flags to the third argument, arg, taken as an integer of type int.
Only certain flags can be set; see fcntl (5). It is not possible to set both O_NDELAY
and O_NONBLOCK.
F_GETLK Get the first lock that blocks the lock described by the variable of type struct
flock pointed to by the third argument, arg , taken as a pointer to type struct
flock. The information retrieved overwrites the information passed to fcntl()
in the flock structure. If no lock is found that would prevent this lock from being
created, the structure is passed back unchanged, except that the lock type is set to
F_UNLCK.
F_SETLK Set or clear a file segment lock according to the variable of type struct flock
pointed to by the third argument, arg, taken as a pointer to type struct flock
(see fcntl (5)). The cmd F_SETLK is used to establish read ( F_RDLCK ) and write
( F_WRLCK ) locks, as well as to remove either type of lock ( F_UNLCK ). If a read or
write lock cannot be set, fcntl() returns immediately with an error value of 1.
F_SETLKW This cmd is the same as F_SETLK except that if a read or write lock is blocked by
other locks, the process will sleep until the segment is free to be locked.
F_GETLK64 Same as F_GETLK, except arg is a pointer to struct flock64 instead of
struct flock.
HP-UX 11i Version 3: March 2011 1 Hewlett-Packard Company 1

Summary of content (8 pages)