In bash script, I have a program like this
for i in {1..1000}
do
foo i
done
Where I call the function foo
1000 times with parameter i
If I want to make it run in multi-process, but not all at once, what should I do?
So if I have
for i in {1..1000}
do
foo i &
done
It would start all 1000 processes at once, which is not what I want.
Is there a way to make sure that there is always 100 process running? If some processes are finished, start some new ones, until all 1000 iterations are done. Alternatively, I could wait till all 100 are finished and run another 100.
moreutils
package that includes a program described inman -s 1 parallel
. It appears to be a perfect fit for your requirements.