How To Run Parallel Jobs/Process/Programs in Bash

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/how-to-run-parallel-jobsprocessprograms-in-bash/
PINTEREST
PINTEREST
INSTAGRAM

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 is 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 in 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 command is issued we have two line which show the commands processes and their related PID and there is also information about the background jobs in square brackets job id. Both command will start in 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 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 very useful tool which can start multiple jobs in 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 Add New User Account To Linux

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/how-to-run-parallel-jobsprocessprograms-in-bash/
PINTEREST
PINTEREST
INSTAGRAM