DOTLOCKFILE(1)
๐ DOTLOCKFILE โ bestie's guide to lockfiles ๐
okay so first things first, the tea: this is dotlockfile(1) from the Cistron Utilities crew. yeah. the Cistron girlies. iconic of them honestly.
โจ NAME โจ
dotlockfile โ the utility that manages lockfiles, fr fr. it's giving "I keep your stuff safe so two programs don't fight over it" energy ๐
๐ธ SYNOPSIS ๐ธ
dotlockfile -l [-r retries] [-i interval] [-p] [-q] <-m | lockfile>
dotlockfile -l [-r retries] [-i interval] [-p] [-q] <-m | lockfile> [-P]
cmd args ...
dotlockfile -u | -t
like, copy that exactly bestie, don't get cute with it ๐
๐ฆ DESCRIPTION ๐ฆ
so dotlockfile is a command line utility that reliably creates, tests and removes lockfiles. and when I say reliably I mean RELIABLY โ it works on local and NFS filesystems, because the two crucial steps (testing whether a lockfile already exists, and then creating it) are performed atomically by a single call to link(2). one call. no window for anybody to sneak in between. that's the whole magic trick โจ
if you wanna know the algorithm it uses, the manpage lockfile_create(3) spills all the deets.
it's installed with the attribute SETGID mail, which means it can also lock and unlock mailboxes even when the mailspool directory is only writable by group mail. so yes, it can do the thing you can't do yourself. main character energy, honestly.
the name dotlockfile comes from the way mailboxes are locked for updates on a lot of UNIX systems: a lockfile gets created with the same filename as the mailbox but with the string ".lock" appended.
and the reason it's called dotlockfile and not something shorter? the names dotlock and lockfile were already taken โ hence the name dotlockfile :). the struggle was real ๐
๐ OPTIONS ๐
-lโ create a lockfile if no preexisting valid lockfile is found; otherwise wait and retry according to option-r. the retry interval can be explicitly set with option-i. and plot twist:-lis the default, so you can literally just leave it off. no cap.
a lockfile is treated as valid,
- if it holds the process-id of a running process,
- or if it does not hold any process-id and has been touched less than 5 minutes ago (timestamp is younger than 5 minutes).
-rretries โ the number of timesdotlockfileretries to acquire the lock if it failed the first time, before giving up. the initial sleep after failing to acquire the lock is 5 seconds. after each retry the sleep interval is increased incrementally by 5 seconds, up to a maximum sleep of 60 seconds between tries โ unless it's overridden by-i. the default number of retries is 5. to try only once, use-r 0. to try indefinitely, use-r -1(yes, negative one, she's committed ๐ญ).-iinterval โ sets a consistent retry interval. no more escalating naps, just one steady vibe.-uโ remove a lockfile. bye bestie ๐-tโ touch an existing lockfile (update the timestamp). useful for lockfiles on NFS filesystems. for lockfiles on local filesystems the-poption is preferable.-pโ write the process-id of the calling process (or ofdotlockfileitself if a command is executed) into the lockfile. also, when testing for an existing lockfile, check the contents for the process-id of a running process to verify if the lockfile is still valid. obviously this is only useful for lockfiles on local filesystems.-mโ lock or unlock the current user's mailbox. the path to the mailbox is the default system mailspool directory (usually/var/mail) with the username as gotten fromgetpwuid()appended. if the environment variable$MAILis set, that is used instead. then the string".lock"is appended to get the name of the actual lockfile.-qโ don't print warnings or errors to the standard error output. used internally byliblockfilewhen it spawnsdotlockfileas a helper program. she's shy ๐คซ-Pโ on a successful "lock and spawn command", don't exit with status zero, but pass through the exit value of the spawned command.- lockfile โ the lockfile to be created or removed. must not be specified if the
-moption is given. pick a lane bestie. - command argument ... โ create lockfile, run the command, wait for it to exit, and remove lockfile. the full babysitting package ๐ซถ
โญ RETURN VALUE โญ
zero on success, non-zero on failure. when locking (the default, or with the -l option), dotlockfile returns the same values as the library function lockfile_create(3).
and here's a lil ray of sunshine: unlocking a non-existent lockfile is not an error. she's forgiving like that.
unless the -P option was supplied, when a command is executed, the return value does not correspond with that of the command that was run. if locking and unlocking was successful, the exit status is zero.
๐ NOTES ๐
the lockfile is created exactly as named on the command line. the extension ".lock" is not automatically appended. you say what you mean, she does what you say.
this utility is a lot like the lockfile(1) utility included with procmail, and the mutt_dotlock(1) utility included with mutt. however, the command-line arguments differ, and so does the return status. it is believed that dotlockfile is the most flexible implementation, since it automatically detects when it needs to use privileges to lock a mailbox, and does it safely. like she just knows. iykyk ๐
oh and psa: the above mentioned lockfile_create(3) manpage lives in the liblockfile-dev package.
๐ BUGS ๐
none known.
(genuinely. not one. she's flawless and she knows it ๐ โจ)
๐ฅ SEE ALSO ๐ฅ
๐ AUTHOR ๐
Miquel van Smoorenburg
okay that's the whole page, bestie, you're basically a lockfile expert now, go lock something (responsibly) ๐
shoutout to the very last line of the original: this was DOTLOCKFILE(1) dated January 10, 2017, and yeah, she's still out here serving. vintage but never outdated ๐ธ๐ฆ๐
๐ฆ where this page comes from
- alpine 3.22: liblockfile-doc 1.17-r4 ยท LGPL-2.0-or-later AND GPL-2.0-or-later
- alpine 3.23: liblockfile-doc 1.17-r4 ยท LGPL-2.0-or-later AND GPL-2.0-or-later
- alpine 3.24: liblockfile-doc 1.17-r4 ยท LGPL-2.0-or-later AND GPL-2.0-or-later
- arch rolling: liblockfile 1.17_2-1 ยท GPL
- debian bookworm: liblockfile-bin 1.17-1+b1 ยท LGPL-2.0-or-later
- debian trixie: liblockfile-bin 1.17-2 ยท LGPL-2.0-or-later
- epel 10: liblockfile 1.17-11.el10_2 ยท GPL-2.0-or-later AND LGPL-2.0-or-later
- fedora 43: liblockfile 1.17-11.fc43 ยท GPL-2.0-or-later AND LGPL-2.0-or-later
- fedora 43: liblockfile 1.17-11.fc43 ยท GPL-2.0-or-later AND LGPL-2.0-or-later
- fedora 44: liblockfile 1.17-12.fc44 ยท GPL-2.0-or-later AND LGPL-2.0-or-later
- fedora 44: liblockfile 1.17-12.fc44 ยท GPL-2.0-or-later AND LGPL-2.0-or-later
- nixos 26.05: liblockfile 1.17
- nixpkgs unstable: liblockfile 1.17
- opensuse-leap 16.0: lockfile 1.17-bp160.1.12 ยท GPL-2.0-or-later AND LGPL-2.0-or-later
- opensuse-leap 16.0: lockfile 1.17-bp160.1.12 ยท GPL-2.0-or-later AND LGPL-2.0-or-later
- opensuse-leap 16.0: lockfile 1.17-bp160.1.12 ยท GPL-2.0-or-later AND LGPL-2.0-or-later
- opensuse-leap 16.0: lockfile 1.17-bp160.1.12 ยท GPL-2.0-or-later AND LGPL-2.0-or-later
- ubuntu jammy: liblockfile-bin 1.17-1build2 ยท LGPL-2.0-or-later
- ubuntu noble: liblockfile-bin 1.17-1build3 ยท LGPL-2.0-or-later
- ubuntu questing: liblockfile-bin 1.17-2build1
- ubuntu resolute: liblockfile-bin 1.17-2build2 ยท LGPL-2.0-or-later
- ubuntu stonking: liblockfile-bin 1.17-2build2 ยท LGPL-2.0-or-later
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms