Amriteya
Amriteya

Reputation: 1172

Wait for one of two processes in shell script

I am running a couple of background processes in my shell script. I want to exit the script when one of the two processes exit.

If I apply:

wait $PID1
wait $PID2

It'll will wait for process 1 to complete and then wait for process 2. Same happens for:

command 1 && command 2 && wait

Is there any way I could perform an or operation on the wait command?

Upvotes: 2

Views: 129

Answers (1)

Jens
Jens

Reputation: 72619

You can trap SIGCHLD:

trap 'exit 0' SIGCHLD

Upvotes: 1

Related Questions