Seth Woolley's Man Viewer

Manual for flock - man 1 flock

([section] manual, -k keyword, -K [section] search, -f whatis)
man plain no title

FLOCK(1)                         User Commands                        FLOCK(1)

       flock(1,2)  -  acquire  a file(1,n) lock and then execute a command with the lock

       flock(1,2) [ --shared | --timeout=seconds ] lockfile command ..

       Acquire a file(1,n) lock using the flock(1,2)(2) system call and then execute the
       given  command with the lock held.  Depending on the options given, the
       lock can be either exclusive or shared, and the behavior in(1,8)  the  event
       of  lock contention can be specified as either waiting indefinitely for
       the lock to become available (the default), or failing if(3,n) the lock does
       not  become  available after a specific time(1,2,n), which can be specified as
       zero to make the command not wait at all.

              Acquire a shared lock.  Acquiring a shared lock  does  not  stop
              others  from  acquiring  a  shared lock, but it will stop others
              from acquiring an  exclusive  lock.   Conversely,  acquiring  an
              exclusive  lock  (the  default)  stops both exclusive and shared
              attempts to acquire the lock.  Typically, a shared lock is  used
              if(3,n)  a  command  is  just  going  to read(2,n,1 builtins) the locked data, and an
              exclusive lock is used if(3,n) the command might write(1,2) to it.

              Abort if(3,n) the lock cannot be acquired before n  seconds.   For  a
              completely  non-blocking  attempt  to  acquire  a  lock, specify
              --timeout=0.  The timer applies only to the attempt  to  acquire
              the  lock.  As soon as the lock is acquired, the timeout(1,3x,3x cbreak) is can-
              celled.  The command to be run is not subject to the timeout.

EXAMPLES (invoking some imaginary programs)
       flock(1,2) /etc/passwd(1,5) read-and-write-to-passwd

       flock(1,2) --shared /etc/passwd(1,5) just-read-something-from-passwd

       flock(1,2) --timeout=0 /sys /usr/local/bin/update-hotplug /sys

       Written by Adam J. Richter

flock(1,2) (util-linux)               November 2004                        FLOCK(1)

References for this manual (incoming links)