问题
Following works for me:
>sleep 20 &
[1] 30414
>sleep 30 &
[2] 30415
>wait $30414 $30415
This works all right until I want to write this into tmp.csh
In my tem.csh file
sleep 20 &
set pid1=$!
sleep 30 &
set pid2=$!
When it comes to "wait"
wait $pid1 $pid2 => too many arguments
wait $pid1 => too many arguments
wait \$$pid1 => too many arguments
wait $($pid1) => Illegal variable name
How shall I write it?
And this question is for a solution of How can I wait until specified "xterm" finished?
回答1:
The "wait" command will not wait for specific PIDs. Try the following in CSH to wait for specific PIDs:
#!/bin/csh -f
sleep 30 &
set pid1 = $!
sleep 40 &
set pid2 = $!
while ( `ps -p "$pid1,$pid2" | wc -l` > 1 )
sleep 1
end
回答2:
This works for me in tcsh:
#!/bin/tcsh
time
sleep 10 &
sleep 5 &
wait
time
It looks like that wait doesn't take any argument, just waits until every backgorunded process finish.
来源:https://stackoverflow.com/questions/18104195/wait-for-two-pid-in-c-shell