I'm ptrace'ing a process. After fork/execl and then a wait
on the child, I'm getting a status of 2943. I'm testing for failure, but waitpid
reports non-failure. I've looked in <sys/wait.h>
, but the value is not defined and does not appear to be a bit mask.
Any ideas on where I should look?
int DoParentProcess(int childPid)
{
int err, ret, status;
for( ; ; )
{
ret = waitpid(childPid, &status, 0);
err = errno;
///////////////////////////////////////
if(ret == -1)
{
cerr << "Failed to wait on child process, errno = " << err << endl;
return err;
}
///////////////////////////////////////
cout << "Parent: wait status = " << status << endl;
if(WIFEXITED(status))
break;
///////////////////////////////////////
ret = ptrace(PTRACE_CONT, childPid, 0, 0);
err = errno;
if(ret == -1)
{
cerr << "Failed to continue child process, errno = " << err << e开发者_StackOverflow中文版ndl;
return err;
}
}
return 0;
}
The value from waitpid
should not be directly used. Instead, the provided macros should be used to extract relevant bits. For example, WIFEXITED
, WEXITSTATUS
, and WTERMSIG
.
精彩评论