SHLOCK(1)
π shlock(1) β InterNetNews Documentation β¨
okay bestie, settle in, because this one's a little utility from InterNetNews docs and it's lowkey iconic for shell scripts π
πΈ NAME πΈ
shlock β literally just makes lock files so your shell scripts don't step on each other π
β¨ SYNOPSIS β¨
shlock [-b|-c|-u] -f name -p pid
that's the whole vibe. three optional flags, two required ones. periodt π«Ά
π¦ DESCRIPTION π¦
so here's the tea π: shlock tries to create a lock file named name and write the process ID pid into it. that's the whole job. main character energy, honestly.
if the file already exists, shlock reads the process ID out of it and checks whether that process is currently running. if the process exists? nope, the file will not be created. respectfully declined π
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. no cap, that's your signal π₯
also!! there's a Perl wrapper around shlock you can use via the INN::Utils::Shlock module β¨
π OPTIONS π
-bβ process IDs are normally read and written in ASCII. but if you pass-b, they get written as a binaryintinstead π§-cβ with-c,shlockwill not create a lock file. instead it just uses the file to see if the lock is held by another program. if the lock is valid β exits with a non-zero status π; if the lock is not valid (i.e. invokingshlockwithout the flag would have succeeded) β exits with a zero status π-fname β name is the name of the lock fileshlockattempts to create. if the file already exists, it reads the process ID from the file and exits with a non-zero status if that process is currently active π«Ά-ppid β pid is the process ID to write into the file name π-uβ for compatibility with other systems,-uis accepted as a synonym for-b, since binary locks are used by many UUCP packages β
π EXAMPLES π
here's how shlock gets used inside a shell script, bestie β copy it, it's cute:
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
the trap line is doing the cleanup, the shlock line is doing the vibe check, and the else is your "sorry bestie, somebody's already in here" π¦
π HISTORY π
written by Rich $alz <rsalz@uunet.uu.net> for InterNetNews, after a description of HDB UUCP locking given by Peter Honeyman β and then improved by Berend Reitsma to solve a race condition (the classic π). later converted to POD by Julien Elie. slay, all of them π
π SEE ALSO π
and that's the page!! this lil' beauty is from INN 2.7.2, dated 2022-07-10 β till next time, mwah π ππΈ
π¦ where this page comes from
- epel 9: inn 2.7.2-1.el9 Β· 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