thundium
thundium

Reputation: 1063

How can I wait until specified "xterm" finished?

In my c-shell file, I did something like:

xterm -e "source xxxx0" &

xterm -e "source xxxx1" &

wait

code....

It works fine that code after "wait" will be executed after the two xterm finished.

But it also gives problem. If I have some ps open, like an txt file opened by geditn, or I have an eclipse open, it will hung there since "wait" is waiting for all jobs to be finished.

So how can I let "wait" only wait for those two xterm jobs.

Or in another word, I want those two "xterm" run concurrently. And after they both done, the code can be continued. How shall I do that?

Thank you very much

Upvotes: 0

Views: 813

Answers (1)

ahilsend
ahilsend

Reputation: 931

Tell wait the process ids it should wait for:

xterm ... &
pid1=$!

xterm ... &
pid2=$!

wait $pid1 $pid2

That's assuming you use a shell where wait supports multiple arguments (bash,zsh, ...). If you use sh for portability, then you have to do two waits:

wait $pid1
wait $pid2

This will wait untill both are finished. If the second finishes before the first, the wait will immediately return.

Upvotes: 2

Related Questions