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
WNOHANGwas specified and one or more child(ren) specified bypidexist, but have not yet changed state, then0is 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
加载中,请稍侯......
精彩评论