Run multiple programs at once during initialization / bash script

Hello, I am working with a simulator that uses rcS scripts to load, this is my script

cd /tests ./test1 & ./test2 & ./test3 & ./test4 exit 

What I want is to run the whole test at the same time and that the exit command is only executed when all previous tests have completed. And not only when test 4 is over, is this possible ?. Thanks.

+4
source share
3 answers

You can use wait:

 ./test1 & ./test2 & ./test3 & ./test4 & wait 

On the bash man page:

wait [n ...] Wait for each specified process and return its completion status. Each n may be a process identifier or job specification; if a job specification is specified, all processes in this pipeline are waiting for work. If n is not specified, all current active child processes wait, and the return status is zero. If n indicates a non-existent process or task, the return status is 127. Otherwise, the return status is the exit status of the last process or work expected.

+8
source

xargs can support parallel

So like this:

 seq 4|xargs -i -n 1 -P 4 ./test{} 
+5
source

Something along the lines

 cd /tests ./test1 & ./test2 & ./test3 & ./test4 & wait exit 

(I assume bash shell)

+4
source

All Articles