本文介绍了如何等待非子进程退出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有关的子进程中,的wait()
和 waitpid函数()
功能可以用来中止执行目前的进程,直到孩子已退出。但此功能不能用于非子进程。
For child processes, the wait()
and waitpid()
functions can be used to suspends execution of the current process until a child has exited. But this function can not be used for non-child processes.
有另一种功能,可以等待任何进程?
Is there another function, which can wait for exit of any process ?
推荐答案
没有等同于等待()
。通常的做法是使用杀(PID,0)
并寻找返回值-1 错误号
和轮询 ESRCH
来表示该过程已经一去不复返了。
Nothing equivalent to wait()
. The usual practice is to poll using kill(pid, 0)
and looking for return value -1 and errno
of ESRCH
to indicate that the process is gone.
这篇关于如何等待非子进程退出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!