This utility manages
locks from within shell scripts or the command line.
The first and second forms wraps the lock around the executing a command, in a manner similar to
It locks a specified file or directory, which is created (assuming appropriate
permissions), if it does not already exist.
The third form is convenient inside shell scripts, and is usually
used the following manner:
flock -n 9
# ... commands executed under lock ...
The mode used to open the file doesnt matter to flock; using
> or >> allows the lockfile to be created if it does not
already exist, however, write permission is required; using <
requires that the file already exists but only read permission is
By default, if the lock cannot be immediately acquired, flock
waits until the lock is available.