wait for two PID in c-shell

帅比萌擦擦* 提交于 2019-12-12 02:23:18

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!