fcntl.2 (2011 03)

f
fcntl(2) fcntl(2)
F_SHARE Sets a share reservation on a file with the specified access mode and designates
which types of access to deny. The details of the file share reservation request are
specified using the third argument arg, which should be a pointer to a
struct
fshare (defined in <sys/fcntl.h>
). See the File Share Reservations section
below.
F_UNSHARE Removes an existing share reservation.
F_SETFIFOENH
If fildes refers to fifo, the performance of the asynchronous fifo reads or writes may
improve in multiprocessor environment when multiple threads are operating on the
same fildes. This cmd will work only if HP’s optional
FIFOENH product is installed
on the system.
An example using
F_SETFIFOENH follows:
int
main(int argc, char **argv)
{
int fd;
/* Create a file*/
if (mkfifo( /tmp/fifotest", S_IRUSR|S_IWUSR) == -1)
{
printf( Error in creating fifo");
exit(1);
}
/* Opening the fifo file */
if ((fd = open( /tmp/fifotest",O_RDWR)) == -1)
{
printf( Error in opening fifo );
exit(1);
}
/* setting the F_SETFIFOENH flag on the opened file */
fcntl(fd,F_SETFIFOENH,NULL);
}
A read lock prevents any other process from write-locking the protected area. More than one read lock
can exist for a given segment of a file at a given time. The file descriptor on which a read lock is being
placed must have been opened with read access.
A write lock prevents any other process from read-locking or write-locking the protected area. Only one
write lock can exist for a given segment of a file at a given time. The file descriptor on which a write lock
is being placed must have been opened with write access.
The structure
flock describes the type (l_type), starting offset (l_whence), relative offset
(l_start), size (l_len), and process ID (l_pid) of the segment of the file to be affected. The process
ID field is only used with the F_GETLK cmd to return the value of a block in lock. Locks can start and
extend beyond the current end of a file, but cannot be negative relative to the beginning of the file. A lock
can be set to always extend to the end of file by setting l_len to zero (0). If such a lock also has
l_start set to zero (0), the whole file will be locked. Changing or unlocking a segment from the middle
of a larger locked segment leaves two smaller segments for either end. Locking a segment already locked
by the calling process causes the old lock type to be removed and the new lock type to take effect. All
locks associated with a file for a given process are removed when a file descriptor for that file is closed by
that process or the process holding that file descriptor terminates. Locks are not inherited by a child pro-
cess in a fork() system call.
When enforcement-mode file and record locking is activated on a file (see chmod(2)), future
creat(),
open(), read(), write(), truncate(), and ftruncate() system calls on the file are affected by
the record locks in effect.
HP-UX 11i Version 3: March 2011 3 Hewlett-Packard Company 3