dbs9654
dbs9654

Reputation: 13

Waiting for end of at least one job in bash

let's consider a following snippet:

for ((i = 1 ; i <= $N ; i++)); do
  sleep 1000 &
done

How to wait for end of at least one subprocess? And then, exit all of them. Is it possible?

Upvotes: 0

Views: 73

Answers (1)

choroba
choroba

Reputation: 242403

Use wait -n to wait for at least one job to finish.

To kill all the remaining jobs, you can use

jobs -p | xargs kill

Upvotes: 2

Related Questions