Use multiple processors in bash by running commands in parallel


dual_quad_core_processorsYou’ve got a dual quad core system and you want to run jobs on all eight “processors” in a bash shell script. This is how you can do it:

====#!/bin/bash====

====xargs vs xjobs====
There are also utilities already written just for this type of thing, but forget xargs. Check out xjobs instead.

xjobs reads job descriptions line by line and executes them in parallel. It limits the number of parallel executing jobs and starts new jobs when jobs finish. If no utility is given as an argument to xjobs, then the first argument on every job line will be used as utility. xjobs support I/O redirection, which makes some applications possible that cannot be done with GNU’s xargs. xjobs also determines the number of processors automatically, whereas xargs must be told how many processes to start.


Posted on January 15th, by admica in Linux.

2 thoughts on “Use multiple processors in bash by running commands in parallel

  1. Thanks for your information. I think it is useful for many clients.