SHLOCK(8)
πΈ NAME πΈ
okay so bestie, this is shlock β the manual page for making lock files for use in shell scripts. yes that's the whole vibe, and it's lowkey iconic π
β¨ SYNOPSIS β¨
shlock [-b|-c|-u] -f name -p pid
literally that's it. she's compact, she's efficient, she ate π
π¦ DESCRIPTION π¦
so here's the tea, bestie π« β shlock tries to create a lock file named name and write the process ID pid into it. that's her whole job and she does it slayfully.
but wait, there's more (there's always more). if the file already exists, shlock is gonna read the process ID from the file and test to see whether the process is currently running. if the process exists, then the file will not be created. periodt. no cap.
shlock exits with a zero status if it could create the lock file, or non-zero if the file refers to a currently active process. so like, zero = you got the lock π, non-zero = somebody else is holding it π
also there's a Perl wrapper around shlock you can use via the INN::Utils::Shlock module, if that's your thing π
π OPTIONS π
okay bestie, here's the full roster, no skipping, every single one:
-bβ so process IDs are normally read and written in ASCII, right? but if the-bflag is used, then they'll be written as a binaryint. funky. weird. love it π-cβ if the-cflag is used, thenshlockwill not create a lock file, but will instead use the file to see if the lock is held by another program. if the lock is valid, the program will exit with a non-zero status; if the lock is not valid (i.e. invokingshlockwithout the flag would have succeeded), then the program will exit with a zero status. she's just checking, not taking π§-fname β name is the name of the lock fileshlockattempts to create. if the file already exists, it will read the process ID from the file and exit with a non-zero status if this process is currently active. π-ppid β pid is the process ID to write into the file name. simple as that π-uβ for compatibility with other systems, the-uflag is accepted as a synonym for-b, since binary locks are used by many UUCP packages. history, bestie ποΈ
π EXAMPLES π
the following example shows how shlock would be used within a shell script β look at her go, main character energy fr fr π₯
LOCK=<pathrun in inn.conf>/LOCK.send
trap 'rm -f ${LOCK} ; exit 1' 1 2 3 15
if shlock -p $$ -f ${LOCK} ; then
# Do appropriate work.
else
echo "Locked by `cat ${LOCK}`"
fi
see how she traps those signals and cleans up after herself? that's called being a responsible queen π«Ά
π HISTORY π
written by Rich $alz <rsalz@uunet.uu.net> for InterNetNews after a description of HDB UUCP locking given by Peter Honeyman, and improved by Berend Reitsma to solve a race condition. then converted to POD by Julien Elie. the lore is deep, iykyk πβ¨
πΈ SEE ALSO πΈ
INN::Utils::Shlock(3pm)β go read it bestie, it's the Perl wrapper β¨
ngl this whole thing is giving "tiny tool, huge responsibility" and honestly? obsessed π
and that's the page, bestie! brought to you by INN 2.7.4, dated 2022-07-10, filed under SHLOCK(8) β mwah, go lock something responsibly π
ππ¦
π¦ where this page comes from
- arch rolling: inn 2.7.4-4 Β· ISC
- epel 10: inn 2.7.4-5.el10_3 Β· ISC AND BSD-3-Clause AND BSD-4-Clause AND FSFAP AND (GPL-1.0-or-later OR Artistic-1.0-Perl) AND GPL-3.0-or-later WITH Bison-exception-2.2 AND LicenseRef-Fedora-Public-Domain AND MIT AND NTP
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms