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

Community
  • 1
  • 1
fabioln79
  • 395
  • 2
  • 5
  • 16

1 Answers1

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
Davide Berra
  • 6,387
  • 2
  • 29
  • 50