Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ flock(2) — UTek W2.3

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

close(2)

dup(2)

execve(2)

fork(2)

open(2)



FLOCK(2)                COMMAND REFERENCE                FLOCK(2)



NAME
     flock - apply or remove an advisory lock on an open file

SYNOPSIS
     #include <sys/file.h>

     flock(fd, operation)
     int fd, operation;

DESCRIPTION
     Flock applies or removes an advisory lock on the file
     associated with the file descriptor fd.  A lock is applied
     by specifying an operation.  Operation is constructed by
     or'ing together some combination of the following, defined
     in <sys/file.h>:

          #define   LOCK_SH   1    /* shared lock */
          #define   LOCK_EX   2    /* exclusive lock */
          #define   LOCK_NB   4    /* don't block when locking */
          #define   LOCK_UN   8    /* unlock */

     A lock is applied by specifying either LOCK_SH or LOCK_EX,
     possibly or'd with LOCK_NB.  LOCK_UN will unlock an existing
     lock.

     Advisory locks allow cooperating processes to perform
     consistent operations on files, but do not guarantee
     consistency (i.e. processes may still access files without
     using advisory locks possibly resulting in inconsistencies).

     The locking mechanism allows two types of locks:  shared
     locks and exclusive locks.  At any time multiple shared
     locks may be applied to a file, but at no time are multiple
     exclusive, or both shared and exclusive, locks allowed
     simultaneously on a file.

     A shared lock may be upgraded to an exclusive lock, and vice
     versa, simply by specifying the appropriate lock type; this
     results in the previous lock being released and the new lock
     applied (possibly after other processes have gained and
     released the lock).

     Requesting a lock on an object which is already locked
     normally causes the caller to be blocked until the lock may
     be acquired.  If LOCK_NB is included in operation, then this
     will not happen; instead the call will fail and the error
     EWOULDBLOCK will be returned.

     Locks are on files, not file descriptors.  That is, file
     descriptors duplicated through dup(2) or fork(2) do not
     result in multiple instances of a lock, but rather multiple
     references to a single lock.  If a process holding a lock on



Printed 10/17/86                                                1





FLOCK(2)                COMMAND REFERENCE                FLOCK(2)



     a file forks and the child explicitly unlocks the file, the
     parent will lose its lock.

     Processes blocked awaiting a lock may be awakened by
     signals.

DIAGNOSTICS
     The flock call fails if:

     [EWOULDBLOCK]       The file is locked and LOCK_NB was
                         specified.

     [EBADF]             The argument fd is an invalid
                         descriptor.

     [EOPNOTSUPP]        The argument fd refers to a socket, not
                         to a file.

     [EINVAL]            The argument operation is an invalid
                         request.

RETURN VALUE
     Upon successful completion, a value of 0 is returned.
     Otherwise, a value of -1 is returned and errno is set to
     indicate the error.

SEE ALSO
     close(2), dup(2), execve(2), fork(2), open(2).



























Printed 10/17/86                                                2





































































%%index%%
na:72,92;
sy:164,466;
de:630,2244;3018,171;
di:3189,554;
rv:3743,236;
se:3979,181;
%%index%%000000000116

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026