[英]waitpid for child process not succeeding
I am starting a process using execv
and letting it write to a file. 我正在使用
execv
启动一个进程,并使其写入文件。 I start a thread simultaneously that monitors the file so that it's size does not exceed a certain limit using stat.st_size
. 我同时启动一个线程来监视文件,以便使用
stat.st_size
使其大小不超过特定限制。 Now, when the limit is hit, I waitpid
for the child process, but this throws an error and the process I start in the background becomes a zombie. 现在,当达到限制,我
waitpid
子进程,但是这将引发一个错误,我在后台启动过程将成为僵尸。 When I do the stop using the same waitpid
from the main thread, the process is killed without becoming a zombie. 当我从主线程使用相同的
waitpid
停止时,该进程将被杀死而不会成为僵尸。 Any ideas? 有任何想法吗?
Edit: The errno
is 10 and waitpid
returns -1. 编辑:
errno
为10, waitpid
返回-1。 This is on a linux platform. 这是在linux平台上。
This is difficult to debug without code, but errno
10 is ECHILD
. 没有代码很难调试,但是
errno
10是ECHILD
。
Per the man page, this is returned as follows: 对于手册页,返回如下:
ECHILD
(forwaitpid()
orwaitid()
) The process specified bypid
(waitpid()
) oridtype
andid
(waitid()
) does not exist or is not a child of the calling process.ECHILD
(用于waitpid()
或waitid()
)由pid
(waitpid()
)或idtype
和id
(waitid()
)指定的进程不存在,或者不是调用进程的子进程。 (This can happen for one's own child if the action forSIGCHLD
is set toSIG_IGN
. See also the Linux Notes section about threads.)(如果将
SIGCHLD
的操作设置为SIG_IGN
这可能会发生在自己的孩子身上。另请参阅关于线程的Linux Notes部分。)
In short, the pid
you are specifying is not a child of the process calling waitpid()
(or is no longer, perhaps because it has terminated). 简而言之,您指定的
pid
不是调用waitpid()
的进程的子进程(或者不再是,可能是因为它已终止)。
Note the parenthetical section: 请注意括号部分:
"This can happen for one's own child if the action for SIGCHLD
is set to SIG_IGN
" - if you've set up a signal handler for SIGCHLD
to be SIG_IGN
, the wait
is effectively done automatically, and therefore waitpid
won't work as the child will have already terminated (will not go through zombie state). “如果将
SIGCHLD
的操作设置为SIG_IGN
这可能会发生在自己的孩子身上” -如果您已将SIGCHLD
的信号处理程序设置为SIG_IGN
,则wait
会自动有效地完成,因此waitpid
不会像孩子将已经终止(不会进入僵尸状态)。
"See also the Linux Notes section about threads." “另请参阅有关线程的Linux Notes部分。” - In Linux, threads are essentially processes.
-在Linux中,线程本质上是进程。 Modern linux will allow one thread to wait for children of other threads (provided they are in the same thread group - broadly parent process).
现代linux将允许一个线程等待其他线程的子代(前提是它们在同一线程组中-广泛来说是父进程)。 If you are using Linux prior to 2.4, this is not the case.
如果使用2.4之前的Linux,则不是这种情况。 See the documentation on
__WNOTHREAD
for details. 有关详细信息,请参见
__WNOTHREAD
上的文档。
I'm guessing the thread thing is a red herring, and the problem is actually the signal handler, as this accords with your statement 'the process is killed without becoming a zombie.' 我猜线程问题是一个红色的鲱鱼,实际上是信号处理程序,因为这符合您的说法: “进程被杀死而没有成为僵尸。”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.