0

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.

2 Answers 2

2

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/ &
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks. These make commands are truly running in parallel right... and not just one after the other in background?
It will certainly run in parallel if you have multi processor. With single processor this is going to be time-sliced parallel.
1

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 &

2 Comments

This would work only if the make file would use absolute paths everywhere right
Ah, right. Looks like tivn's answer is more relevant in the case of relative paths.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.