Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running bash jobs in parallel with predefined order prioritization

I want to run 3 jobs (A, B, C) on 2 cores of a machine with >2 cores. I know that:

runtime(A)>runtime(C)

runtime(B)>runtime(C)

It is unknown in advance if runtime(A)>runtime(B) or runtime(A)<runtime(B).

What I want to do is:

  • launch A on core 1
  • launch B on core 2
  • after either one is finished, launch C on the one free core

How can this be achieved (in bash, if possible)?

like image 392
ddrichel Avatar asked Jan 24 '23 20:01

ddrichel


1 Answers

Just tell GNU Parallel it can use 2 cores:

parallel -j 2 ::: jobA jobB jobC

Note that the jobs will run in the order you specified, but the output may come in a different order. If that is an issue, add -k parameter to keep output in order.

like image 123
Mark Setchell Avatar answered Jan 27 '23 11:01

Mark Setchell