Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to write a process-pool bash shell

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.

like image 280
Sili Avatar asked Jun 22 '11 14:06

Sili


1 Answers

Use xargs:

xargs -P <maximum-number-of-process-at-a-time> -n <arguments-per-process> <command> 

Details here.

like image 176
Parag Sarda Avatar answered Sep 22 '22 01:09

Parag Sarda