0

So, I just wanted to know So, I just wanted to know how 2 or more scripts can be run in parallel. I searched a few places and saw mentions of using the '&' in between the various scripts I have but I would not be sure. So, can anyone provide me ideas how it can be possible or various ways I can initiate the process?

Micha Wiedenmann
  • 19,979
  • 21
  • 92
  • 137
jake elias
  • 9
  • 1
  • 2
  • Welcome to Stack Overflow - nice to have you. Please read [How do I ask a good question?](https://stackoverflow.com/help/how-to-ask) and [How to create a Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) to help keeping Stack Overflows content on the highest possible level and increase your chances getting an appropriate answer. – sebast26 Jan 24 '18 at 14:52

2 Answers2

1

Simplest way :

#!/bin/sh

/usr/bin/my-process-1 --args1 &
/usr/bin/my-process-2 --args2 &
/usr/bin/my-process-3 --args3 &

wait
echo all processes complete

Source : https://www.codeword.xyz/2015/09/02/three-ways-to-script-processes-in-parallel/

Alexandre Beaudet
  • 2,774
  • 2
  • 20
  • 29
1

Using & that put the application in the background.

from the man bash.

If a command is terminated by the control operator &, the shell executes the command in the background in a subshell. The shell does not wait for the command to finish, and the return status is 0.

For example.

Running shell script with shell script you can do like this,

#!/bin/bash
sh ./script1 &
sh ./script2 &
danglingpointer
  • 4,708
  • 3
  • 24
  • 42