生成的子进程退出时状态 = 127

发布于 2024-07-18 07:05:02 字数 1014 浏览 7 评论 0原文

我使用 posix_spawnp 执行不同的进程,并检查状态(使用 waitpid)以确保子进程已正确创建。

    int iRet = posix_spawnp(&iPID, zPath, NULL, NULL, argv, environ);       

    if (iRet != 0)
    {
        return false;
    }

    int iState;
    waitpid(static_cast<pid_t>(iPID), &iState, WNOHANG);
    cout << "Wait: PID " << iPID << " | State " << iState << endl;

    if (WIFEXITED(iState)) {
        printf("Child exited with RC=%d\n",WEXITSTATUS(iState));
    }
    else if (WIFSIGNALED(iState)) {
        printf("Child exited via signal %d\n",WTERMSIG(iState));
    }
    else
    {
        printf("Child is NORMAL");
    }

首先,它正确执行,我收到以下消息:

等待:PID 15911 | 状态 0 子进程退出 RC=0

执行同一进程多次后,子进程开始退出,状态为 127。

等待:PID 15947 | 州 32512 儿童 退出时 RC=127

发生这种情况后,我无法让孩子再次生成。 我将上面给出的代码部分包含在 for 循环中,但它无法正确生成。 如果我重新启动父进程,它会工作一段时间,但过了一会儿又会出现同样的问题。

我在这里做错了什么?

I use posix_spawnp to execute different processes and I check the status (with waitpid) to make sure the child was created properly

    int iRet = posix_spawnp(&iPID, zPath, NULL, NULL, argv, environ);       

    if (iRet != 0)
    {
        return false;
    }

    int iState;
    waitpid(static_cast<pid_t>(iPID), &iState, WNOHANG);
    cout << "Wait: PID " << iPID << " | State " << iState << endl;

    if (WIFEXITED(iState)) {
        printf("Child exited with RC=%d\n",WEXITSTATUS(iState));
    }
    else if (WIFSIGNALED(iState)) {
        printf("Child exited via signal %d\n",WTERMSIG(iState));
    }
    else
    {
        printf("Child is NORMAL");
    }

At first this executes properly and I get the following message:

Wait: PID 15911 | State 0 Child exited
with RC=0

After executing the same process several times, the child process starts to exit with status 127.

Wait: PID 15947 | State 32512 Child
exited with RC=127

After this happens, I could not get the child to spawn again. I enclosed the section of code given above in a for loop but it wouldn't spawn properly.
If I restart the parent process, it works for a while but the same problem crops up again after a while.

What am I doing wrong here?

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

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

发布评论

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

评论(2

陌若浮生 2024-07-25 07:05:02

检查

例如:

EINVAL file_actions 或 attrp 指定的值无效。

posix_spawn 和 posix_spawnp 子例程的错误代码受以下条件影响:
如果在调用进程从 posix_spawn 或 posix_spawnp 函数成功返回后发生此错误,则子进程可能会以退出状态 127 退出。

看起来它可能会由于多种原因以 127 退出。

Check this link.

For example:

EINVAL The value specified by file_actions or attrp is invalid.

The error codes for the posix_spawn and posix_spawnp subroutines are affected by the following conditions:
If this error occurs after the calling process successfully returns from the posix_spawn or posix_spawnp function, the child process might exit with exit status 127.

It looks as if it might exit with 127 for a whole host of reasons.

只为守护你 2024-07-25 07:05:02

检查 waitpid() 的返回码以确保没有问题。

代码的读取方式表明您一次仅生成一个子进程(否则无需在循环内调用 waitpid())。 但在这种情况下,我不会期望使用 WNOHANG。

Check the return code from waitpid() to be sure that it isn't having problems.

The way the code reads suggests that you are only spawning one child process at a time (otherwise there'd be no need to call waitpid() within the loop). However in that case I wouldn't expect to use WNOHANG.

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