1

Possible Duplicate:
How to wait in bash for several subprocesses to finish and return exit code !=0 when any subprocess ends with code !=0?

I have the following problem:

I have 3 processes that I put in a script

process1 process2 process3

I want that process 1 and 2 run simultaneously but they have both finished before the process 3 starts.

i guess it is something like the following..but I am not sure about that "wait"

#!/bin/sh ( process1 & process2 & wait process3 ) 

Thank you

Fabio

1
  • 1
    That will do what you want. You do not need the ( ) construct. Commented Feb 5, 2013 at 11:13

1 Answer 1

3

Just save the pid of both processes and wait for both to exit

#!/bin/bash process1 & pid1=$! process2 & pid2=$! wait ${pid1} echo "Return value of process1: $?" wait ${pid2} echo "Return value of process2: $?" process3 
Sign up to request clarification or add additional context in comments.

2 Comments

so the single wait does not make any sense in your opinion?
It works as well. This is just my habit and I think it's better because, if you want, you can check the return value of the processes

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.