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 -b flag is used, then they'll be written as a binary int. funky. weird. love it πŸ’…
  • -c β€” if the -c flag is used, then shlock will 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. invoking shlock without the flag would have succeeded), then the program will exit with a zero status. she's just checking, not taking 🧚
  • -f name β€” name is the name of the lock file shlock attempts 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. πŸ‘‘
  • -p pid β€” pid is the process ID to write into the file name. simple as that πŸ’–
  • -u β€” for compatibility with other systems, the -u flag 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 🌸


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