Apple/BSD:来自 waitpid 的状态 = 2943?

发布于 2024-11-15 02:57:58 字数 970 浏览 7 评论 0原文

我正在跟踪一个进程。在 fork/execl 和子进程 wait 之后,我得到的状态为 2943。我正在测试失败,但 waitpid 报告没有失败。我查看了,但该值未定义并且似乎不是位掩码。

关于我应该去哪里看有什么想法吗?

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 << endl;
      return err;
    }
  }

  return 0;
}

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 << endl;
      return err;
    }
  }

  return 0;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

贪恋 2024-11-22 02:57:58

不应直接使用 waitpid 中的值。相反,应该使用提供的宏来提取相关位。例如,WIFEXITEDWEXITSTATUSWTERMSIG

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文