gpt4 book ai didi

c++ - 生成的子项退出状态 = 127

转载 作者:太空宇宙 更新时间:2023-11-04 12:28:20 24 4
gpt4 key购买 nike

我使用 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");
}

一开始它执行正常,我收到以下消息:

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

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

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

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

我在这里做错了什么?

最佳答案

检查 this link .

例如:

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.

由于种种原因,它似乎可能以 127 退出。

关于c++ - 生成的子项退出状态 = 127,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/759366/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com