1

I'm looking for a way to synchronize some bash scripts on an Ubuntu environment so that no more than X scripts could run at the same time.

I've seen utilities like flock, however they don't grant the ability for more than one script to hold the lock.

I could think of several ways to implement this myself..

  • get a hold of a lockfile, edit its content to mark the number of running scripts, then release it and lock again to reduce the number.

  • create X lockfiles and attempt to lock any of them until succeed

But I would hope that someone already approached this problem and found a stable solution.

Mugen
  • 8,301
  • 10
  • 62
  • 140
  • [parallel](https://www.gnu.org/software/parallel/). – Ipor Sircer Nov 13 '18 at 08:15
  • the scripts are being run by independent agents and therefore could not be synced on their initiation – Mugen Nov 13 '18 at 08:18
  • @tripleee see my comment - this is not the same case – Mugen Nov 13 '18 at 18:06
  • Then please [edit] your question to clarify exactly how the duplicate doesn't solve your problem. There are many near-duplicates on Stack Overflow so you'll probably just end up with a slightly different duplicate. – tripleee Nov 13 '18 at 18:10
  • Something like this maybe? https://stackoverflow.com/questions/13207292/bash-background-process-modify-global-variable – tripleee Nov 13 '18 at 18:15
  • Thanks for your efforts, I couldn't find a good duplicate though I don't doubt it exist. If anyone who came across this finds a matching duplicate or simply an answer, I would appreciate if you write here as a comment. – Mugen Nov 13 '18 at 18:25

0 Answers0