Files
cheatsheet-tldr/tldr/linux/flock
2025-03-29 00:18:23 +00:00

23 lines
785 B
Plaintext

---
syntax: markdown
tags: [tldr, linux]
source: https://github.com/tldr-pages/tldr.git
---
# flock
> Manage locks from shell scripts.
> It can be used to ensure that only one process of a command is running.
> More information: <https://manned.org/flock>.
- Run a command with a file lock as soon as the lock is not required by others:
`flock {{path/to/lock.lock}} {{[-c|--command]}} "{{command}}"`
- Run a command with a file lock, and exit if the lock doesn't exist:
`flock {{path/to/lock.lock}} {{[-n|--nonblock]}} {{[-c|--command]}} "{{command}}"`
- Run a command with a file lock, and exit with a specific error code if the lock doesn't exist:
`flock {{path/to/lock.lock}} {{[-n|--nonblock]}} {{[-E|--conflict-exit-code]}} {{error_code}} {{[-c|--command]}} "{{command}}"`