开发者

Apple/BSD: status = 2943 from waitpid?

开发者 https://www.devze.com 2023-03-11 05:36 出处:网络
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>,

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.

0

精彩评论

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

关注公众号