top | item 44589833

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

34 points| bigattichouse | 7 months ago |github.com

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.

20 comments

order

sluongng|7 months ago

Zacru|7 months ago

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

ethan_smith|7 months ago

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?

forrestthewoods|7 months ago

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.

anitil|7 months ago

While 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|7 months ago

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.

asddfgg55|7 months ago

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

eddythompson80|7 months ago

You enjoyed the project because you love the terminal?