how to write a process-pool bash shell

Sili picture Sili · Jun 22, 2011 · Viewed 23.8k times · Source

I have more than 10 tasks to execute, and the system restrict that there at most 4 tasks can run at the same time.

My task can be started like: myprog taskname

How can I write a bash shell script to run these task. The most important thing is that when one task finish, the script can start another immediately, making the running tasks count remain 4 all the time.

Answer

Parag Sarda picture Parag Sarda · Oct 27, 2013

Use xargs:

xargs -P <maximun-number-of-process-at-a-time> -n <arguments per process> <commnad>

Details here.