wait for two PID in c-shell

2019-08-25 06:32发布

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?

2条回答
小情绪 Triste *
2楼-- · 2019-08-25 07:01

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.

查看更多
闹够了就滚
3楼-- · 2019-08-25 07:10

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
查看更多
登录 后发表回答