FLOCK(1)

NAME
flock - manage file locks from shell scripts

SYNOPSIS
flock [-FhnsuVx] [-w timeout] file|directory command [arguments ...]
flock [-FhnsuVx] [-w timeout] file|directory -c command
flock [-FhnsuVx] [-w timeout] number

DESCRIPTION
The flock utility manages file locks. In the first form command is spawned with arguments. In the second form command is run by the shell by passing it via -c. In the final form a file descriptor number is supplied instead of a path.

The following options are available:

-c, --command
    Pass command to the shell via -c.

-F, --no-fork
    Execute command without forking.

-n, --nonblocking
    Fail rather than wait.

-s, --shared
    Obtain a shared lock.

-u, --unlock
    Unlock an existing lock.

-w, --timeout WAIT
    Wait to acquire the lock for up to WAIT seconds.

-x, --exclusive
    Obtain an exclusive lock. This is the default.

-h, --help
    Display a help message and exit.

-V, --version
    Display version information and exit.

Note: The --shared, --exclusive, --nonblocking, and --unlock options are mutually exclusive.

ENVIRONMENT

SHELL
    When -c is supplied the string specified by SHELL is interpreted as the name of the shell to exec. If the variable SHELL is not set, /bin/sh is used.

EXIT STATUS
When --timeout or --nonblocking are used flock will exit with status 1 if the timeout is reached before acquiring the lock.

EXAMPLES
Acquire an exclusive lock, waiting indefinitely to acquire it:

    $ flock /var/run/lock/example.lock echo locked

Acquire an exclusive lock, waiting up to one minute to acquire it:

    $ flock -w 60 /var/run/lock/example.lock echo locked

SEE ALSO
flock(2)

HISTORY
The flock utility first appeared in util-linux 2.12j. This implementation is a part of chimerautils and was written from scratch.