01.01.2013 Views

AT&T UNIX™PC Unix System V Users Manual - tenox

AT&T UNIX™PC Unix System V Users Manual - tenox

AT&T UNIX™PC Unix System V Users Manual - tenox

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

LOCKING ( 2 ) LOCKING ( 2 )<br />

NAME locking - exclusive access to regions of a file<br />

SYNOPSIS<br />

int locking (filedes, mode, size);<br />

int fildes, mode;<br />

long size;<br />

DESCRIPTION<br />

Locking places or removes a lock on a region of a file. The calling<br />

process has exclusive access to regions it has locked: another pro<br />

cess that attempts to read or write any byte in the locked region<br />

sleeps until the lock is removed. Filedes specifies the file to be<br />

locked or unlocked; file des is a file descriptor returned by an<br />

open, create , pipe, or dup system call. Mode specifies the action:<br />

0 for lock removal; 1 for blocking lock; 2 for checking lock. The<br />

region affected begins at the current file offset associated with<br />

filedes and is size bytes longs. If size is zero, the region affected<br />

ends at the end of the file.<br />

A blocking lock differs from a checking lock only when a process<br />

tries to lock bytes already locked by another process. A process<br />

locked out of a blocking lock goes to sleep until the specified<br />

region is free. A process locked out of a checking lock immediately<br />

gets an error return from locking .<br />

Locking imposes no structure on a UNIX file. A process can arbitrarily<br />

lock any unlocked byte and unlock any locked byte. However,<br />

creating a large number of noncontiguous locked regions can<br />

fill up the lock table and make further locks impossible.<br />

A process is said to be deadlocked if it is sleeping until an unlocking<br />

which cannot occur until after the deadlocked process itself<br />

does some unlocking. Locking , read, and write deliberately fail if<br />

proceeding would cause the calling process to be deadlocked.<br />

Special files and pipes can be locked, but no input/output is<br />

blocked.<br />

SEE ALSO<br />

creat(2), close(2), dup(2), open(2), read(2), write(2).<br />

RETURN VALUE<br />

A return value of -1 indicates an error, with the error value in<br />

errno. An unsuccessful checking lock sets errno to EA CCES . A<br />

system call aborted by an incipient deadlock or by a lock table<br />

overflow sets errno to EDEADLOCK.<br />

WARNING<br />

Do not apply any standard input/output library function to a<br />

locked file.<br />

- 1-

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!