SSh
SSh

Reputation: 189

How to run multiple commands at the same time in bash instead of running one after another?

I need to run more than one command in bash without waiting to finishing first one and starting other command. The commands can be like this inside bash file.

#!/bin/bash
perl test.pl -i file1 -o out1
perl test.pl -i file2 -o out2
and so on

All should run at the same time in different cores instead of running one after another.

Upvotes: 0

Views: 209

Answers (1)

A.P.
A.P.

Reputation: 146

Background them with &:

#!/bin/bash
perl test.pl -i file1 -o out1 &
perl test.pl -i file2 -o out2 &

Or better yet, use GNU parallel. This will allow you to use multiple CPUs and lots more.

Upvotes: 2

Related Questions