开发者

Why Would WIFEXITED Return True on Running Process?

When I wait on a specific running process group that is a child process, WIFEXITED returns true saying the process exited? Is this the way it works? Seems there is something I am not understanding....

if ( waitpid(-pgid, &pstatus, WUNTRACED|WNOHANG ) == -1)
    perror("Wait error");

if ( WIFEXITED(pstatus) ) {
    strncpy(buf,  "Exited", 开发者_开发知识库buf_size);
    return 0;


As you specified WNOHANG I think waitpid is returning 0 and pstatus has the value it had before so WIFEXITED is not working with updated data.

if WNOHANG was specified and one or more child(ren) specified by pid exist, but have not yet changed state, then 0 is returned.


waitpid returns the reaped child pid if it successfully reaps a child. When used with WNOHANG, it immediately returns 0 if no children have exited. Thus, you need to check whether the return value is 0 or a pid before you inspect status. See here for details:

http://pubs.opengroup.org/onlinepubs/9699919799/functions/waitpid.html

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜