Live data from Hacker News

Show HN: Linux CLI tool to provide mutex locks for long running bash ops

github.com

11–20 of 22 posts

Re: Show HN: Linux CLI tool to provide mutex locks for long running bash ops

#12
post #7
post #3

Why not https://man7.org/linux/man-pages/man2/flock.2.html ?

Because that's a syscall ;) 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

Flock can be used in a single line for example for cronjobs.

Flock -s file && script.

Pretty simple. (I forgot the argument, I think is -s..

Re: Show HN: Linux CLI tool to provide mutex locks for long running bash ops

#13
post #7

Earlier quoted context omitted.

Because that's a syscall ;) 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

Why (; flock -n 9 and not ( flock -n 9 ?

It's a "for" loop.

Re: Show HN: Linux CLI tool to provide mutex locks for long running bash ops

#14
post #3

Why not https://man7.org/linux/man-pages/man2/flock.2.html ?

flock is indeed built-in: `flock -xn /tmp/mylock.lock -c "echo running locked command"` does mutex locking in bash. Your tool might offer better ergonomics or features beyond flock's capabilities?

Re: Show HN: Linux CLI tool to provide mutex locks for long running bash ops

#16

I 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.

Sometimes 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.

Re: Show HN: Linux CLI tool to provide mutex locks for long running bash ops

#18
post #17
post #13

Earlier quoted context omitted.

It's a "for" loop.

Could you elaborate?

A for loop in a shell script may sometimes look like this:

`for ((i = 0 ; i 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 ...; )

Re: Show HN: Linux CLI tool to provide mutex locks for long running bash ops

#19
post #7
post #3

Why not https://man7.org/linux/man-pages/man2/flock.2.html ?

Because that's a syscall ;) 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

just pushed a change so now it's:

waitlock myapp & #... do stuff waitlock --done myapp

Re: Show HN: Linux CLI tool to provide mutex locks for long running bash ops

#20

Useful project, I love all things terminal, so I also enjoyed your project.

You enjoyed the project because you love the terminal?

Good 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.
Post reply on HN