Linux command
dotlockfile 命令
文件
复制后可按需替换文件名、目录或参数。
常用示例
Create a lockfile
dotlockfile [file.lock]
Create with retry
dotlockfile -r [5] [file.lock]
Remove a lockfile
dotlockfile -u [file.lock]
Lock with PID
dotlockfile -p [file.lock]
Try lock once
dotlockfile -r [0] [file.lock]
Lock with timeout
dotlockfile -r [10] -l [file.lock]
说明
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.
参数
- -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.
FAQ
What is the dotlockfile command used for?
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.
How do I run a basic dotlockfile example?
Run `dotlockfile [file.lock]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -r _RETRIES_ do in dotlockfile?
Number of retries (0 = try once, -1 = infinite).