How To Run Parallel Jobs/Process/Programs in Bash
We generally run jobs in bash in serial order. There is another way to run jobs which is named parallel. Running parallel means multiple jobs run at the same time.
Send Job To The Background
$ ping google.com & ping poftut.com &
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 parrellel jobs. We can use bash
wait function to wait for finish previously started jobs. In this example we will want jobs
j2 before running
GNU Parallel is very usefull 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 parrellel which will output same time.
parallel ::: “ping poftut.com” “ping google.com”