6 ms·
Show HN: Linux CLI tool to provide mutex locks for long running bash ops
Been exploring claude and spec-based coding, I think it turned out fairly successful. It's just a simple unix-style tool that gives you a single command to use in bash scripts to simplify mutex or semaphore locking of execution.
- asddfgg55 1y agoUseful project, I love all things terminal, so I also enjoyed your project.
- deleted 1y ago[deleted]
- eddythompson80 1y agoYou enjoyed the project because you love the terminal?
- bigattichouse 1y agoGood enough for me. I created the project because I love terminal, and wanted to make something using Claude (to learn how this tool works, strictly for personal enrichment) that solves a small problem I had with some overlapping cron job management.
- eddythompson80 1y agoI was saying that in a questioning tone implying that I think the account is a bot.
- sluongng 1y agoWhy not https://man7.org/linux/man-pages/man2/flock.2.html https://man7.org/linux/man-pages/man2/flock.2.html?
- yjftsjthsd-h 1y agoNit: Probably https://man7.org/linux/man-pages/man1/flock.1.html https://man7.org/linux/man-pages/man1/flock.1.html (shell command, not the underlying libc function)
- anitil 1y agoThis was my first thought and I suppose flock(1) could be used to recreate a lot of this. But it does come with some other quality-of-life improvements like being able to list all currently-used locks, having a lock holdable by N processes etc.
- Zacru 1y agoBecause that's a syscall ;) https://man7.org/linux/man-pages/man1/flock.1.html https://man7.org/linux/man-pages/man1/flock.1.html is the command line manual. I would say one good reason is that waitlock myapp & JOB_PID=$! # ... do exclusive work ... kill $JOB_PID is a lot easier to use and remember than (; flock -n 9 || exit 1; # ... commands executed under lock ...; ) 9>/var/lock/mylockfile
- yjftsjthsd-h 1y agoWhy (; flock -n 9 and not ( flock -n 9 ?
- apopapo 1y agoIt's a "for" loop.
- marklgr 1y agoCould you elaborate?
- apopapo 1y agoA for loop in a shell script may sometimes look like this: `for ((i = 0 ; i < max ; i++ )); do echo "$i"; done` Here this is essentially a "while" loop, meaning it will keep executing the commands as long as we don't reach `exit 1`. (; flock -n 9 || exit 1; # ... commands executed under lock ...; )
- forrestthewoods 1y agoI don’t know the exact threshold at which you should use a real programming language instead of a bash script. But this type of work definitely exceeds it.
- anitil 1y agoWhile in general I'd agree, this isn't necessarily just for bash scripts. It could just wrap the execution of another program allowing higher-level logic to handle concurrency and the low-level program to do it's one-at-a-time job
- bigattichouse 1y agoSometimes you have a cron job that takes longer than it should (but inconsistently so), and another cron job that clobbers what that cron job is doing.
- teddyh 1y agoWe already have lockfile: <https://manpages.debian.org/stable/procmail/lockfile.1.en.html https://manpages.debian.org/stable/procmail/lockfile.1.en.ht...>.