Nikhil
Nikhil

Reputation: 817

Running multiple background processes in script

I have a shell script of the following format :

cd /path/a/
make 
cd /path/b/
make
cd /path/c/
make

Each of the make commands are independent of each other in different directories. I would like to speed up the script by running the different make commands in background using '&'

cd /path/a/
make & 
cd /path/b/
make &
cd /path/c/
make &

Would this work? While the first make command is running, the directory has changed to /path/b/ in the next line. Will this affect the first make commend in the background?

Edit: I am doubtful if this method would actually make this process faster, and wonder if these need to be run in separate processes.

Upvotes: 0

Views: 229

Answers (2)

tivn
tivn

Reputation: 1923

That should be fine. make also accept -C option to change its directory before reading the makefile. So you can do like this as well:

make -C /path/a/ &
make -C /path/b/ &
make -C /path/c/ &

Upvotes: 2

Trent Small
Trent Small

Reputation: 1263

I believe that make takes a -f command line argument where you can simply specify the makefile you want. So, this should work: make -f /path/a/makefile & make -f /path/b/makefile & make -f /path/c/makefile &

Upvotes: 1

Related Questions