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 binary int instead 🧚
  • -c β€” with -c, shlock will 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. invoking shlock without the flag would have succeeded) β†’ exits with a zero status 🌈
  • -f name β€” name is the name of the lock file shlock attempts 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 🫢
  • -p pid β€” pid is the process ID to write into the file name πŸ’–
  • -u β€” for compatibility with other systems, -u is 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