What I would like to achieve is something like this:
#!/bin/sh
concurrency_limit 3
#takes 5 min
(/usr/bin/my-process-1 --args1 && /usr/bin/my-process-2 --args1) &
#takes 10 min
(/usr/bin/my-process-1 --args2 && /usr/bin/my-process-2 --args2) &
#takes 15 min
(/usr/bin/my-process-1 --args3 && /usr/bin/my-process-2 --args3) &
#takes 5 min
(/usr/bin/my-process-1 --args4 && /usr/bin/my-process-2 --args4) &
#takes 10 min
(/usr/bin/my-process-1 --args5 && /usr/bin/my-process-2 --args5) &
#takes 20 min
(/usr/bin/my-process-1 --args6 && /usr/bin/my-process-2 --args6) &
wait max_limit 1200
echo all processes complete
Overall expected maximum execution time is 20 min (-+ 1min) and let's assume I have 3 cpu cores available and I don't want to have more than 3 processes running at the same time.
At the beginning of the script first 3 process started.
After 5 min: 1st process finished and 4th process started.
10th min: 2nd and 4th processes are finished and 5th process started.
15th min: 3rd process is finished.
20th min: 5th process is finished. 6th process is killed without further waiting.
I did a lot of research in stackoverflow but I couldn't find similar usage case:
https://www.codeword.xyz/2015/09/02/three-ways-to-script-processes-in-parallel/
http://www.gnu.org/software/parallel/
Any help or comment would be appreciated thanks.