How To Run Parallel Jobs/Process/Programs in Bash – POFTUT

How To Run Parallel Jobs/Process/Programs in Bash

We generally run jobs in bash in serial order. Serial order means one command runs and after completion other command starts. There is another way to run jobs which are named parallel. Running parallel means multiple jobs run at the same time side by side.

Send Job To The Background

We will start with a simple example where two ping commands will be run in the background at the same time. We will add & to the end of each command. We will ping two domain names google.com and poftut.com.

Send Job To The Background 

Send Job To The Background

We can see from the output that after the command is issued we have two lines which shows the commands processes and their related PID and there is also information about the background jobs in square brackets job id. Both commands will start in the background and will resume up to kill operation or exit.

Wait Before Running New Job

In some cases, we may need to wait before running multiple parallel jobs. We can use the bash wait function to wait for finish previously started jobs. In this example, we will run jobs j1 and j2 before running j3 . But we will wait to complete jobs j1 and j2 before running j3job in the background.

GNU Parallel

GNU Parallel is a very useful tool which can start multiple jobs in a parallel way. We will use the command parallel and specify the jobs we want to run after ::: . In this example, we will run ping poftut.com and ping google.com commands in parallel which will output same time.

LEARN MORE  How To Pass and Parse Linux Bash Script Arguments and Parameters

How To Run Parallel Jobs/Process/Programs in Bash Infographic

How To Run Parallel Jobs/Process/Programs in Bash Infographic

How To Run Parallel Jobs/Process/Programs in Bash Infographic

Leave a Reply

Your email address will not be published. Required fields are marked *