LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

dotlockfile

mailbox-style file locking utility

TLDR

Create a lockfile
$ dotlockfile [file.lock]
copy
Create with retry
$ dotlockfile -r [5] [file.lock]
copy
Remove a lockfile
$ dotlockfile -u [file.lock]
copy
Lock with PID checking
$ dotlockfile -p [file.lock]
copy
Try lock once (no wait)
$ dotlockfile -r [0] [file.lock]
copy
Lock with timeout in seconds
$ dotlockfile -r [10] -l [file.lock]
copy

SYNOPSIS

dotlockfile [options] lockfile

DESCRIPTION

dotlockfile creates lockfiles using the mailbox locking convention (name.lock). It provides atomic file locking for scripts and applications that need to serialize access to resources.The tool handles retry logic, stale lock detection, and PID tracking. With -p, it writes the process ID to the lockfile enabling detection of dead lock holders.dotlockfile is commonly used in shell scripts to prevent concurrent access to files or ensure only one instance of a script runs at a time.

PARAMETERS

LOCKFILE

Path to lockfile to create/remove.
-r RETRIES
Number of retries (0 = try once, -1 = infinite).
-u, --unlock
Remove the lockfile.
-p, --use-pid
Write PID to lockfile.
-l
Lock (default action).
-c, --check
Check if lock is stale.
--help
Display help information.

INSTALL

sudo apt install liblockfile-bin
copy
sudo dnf install liblockfile
copy
sudo pacman -S liblockfile
copy
sudo apk add liblockfile
copy
brew install liblockfile
copy
nix profile install nixpkgs#liblockfile
copy

CAVEATS

Lockfiles on network filesystems may not be reliable. Must manually remove locks on script exit. Stale lock detection requires -p option. Not suitable for high-contention scenarios.

HISTORY

dotlockfile implements the traditional Unix lockfile convention, widely used for mailbox locking. It's part of the liblockfile package providing standardized file locking utilities.

SEE ALSO

flock(1)

Braincup
Open source brain training for math, memory and focus
Braincup mini-games
41 mini-games · Apache-2.0
No ads · No tracking
Play in browser
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid
276 stars
From the maker of Linux Command Library
Copied to clipboard
Braincup
Open source brain training for math, memory and focus. 41 mini-games, from mental arithmetic to Sudoku, N-Back and Solo Chess.
Apache-2.0 licensed · No ads · No tracking · No account
From the maker of Linux Command Library
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid