开发者

Is there a linux command to block until a process exits?

It's just what the question asks. Also, all I have is the PID, and 开发者_Go百科the shell I am running the command from is not necessarily the shell that initially invoked the process. Any ideas?


while ps -p $PID >/dev/null 2>&1; do sleep 1; done

or

while ps -p $PID >/dev/null 2>&1; do :; done


It's not a very neat way to do it, but you may continuously issue kill(2) system calls to the specified pid, putting zero as a signal. The first time kill doesn't succeed by setting errno to ESRCH, you may conclude that the process has exited.


You could check if the dir /proc/PID exists. It seems cleaner than sending multiple signals

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜