flock
linux
Manage file locks from shell scripts. It can be used to ensure that only one instance of a command is running.
More info →Options (3)
-n, --nonblockbooleanRun a command with a file lock, or exit if the lock is currently being held (with exit code 1)
Example:
flock {{[-n|--nonblock]}} {{path/to/lock.lock}} {{command}}-E, --conflict-exit-codebooleanRun a command with a file lock, or exit with a specific error code if the lock is currently being held
Example:
flock {{[-n|--nonblock]}} {{[-E|--conflict-exit-code]}} {{123}} {{path/to/lock.lock}} {{command}}-w, --timeoutbooleanRun a command with a file lock, waiting up to 10 seconds for the lock to be available before giving up
Example:
flock {{[-w|--timeout]}} 10 {{path/to/lock.lock}} {{command}}Examples (5)
Run a command with a file lock, or exit if the lock is currently being held (with exit code 1)
Run a command with a file lock, or exit with a specific error code if the lock is currently being held
Run a command with a file lock, waiting up to 10 seconds for the lock to be available before giving up
made by @shridhargupta | data from tldr-pages