我试图确定执行是否通过检查waitpid函数的结果失败()。但是,即使当我跑,我知道失败并写入这个问题到stderr命令,检查以下从未登记。这段代码可能有什么错误?叉/ EXEC/waitpid函数问题
感谢您的任何帮助。
pid_t pid; // the child process that the execution runs inside of.
int ret; // exit status of child process.
child = fork();
if (pid == -1)
{
// issue with forking
}
else if (pid == 0)
{
execvp(thingToRun, ThingToRunArray); // thingToRun is the program name, ThingToRunArray is
// programName + input params to it + NULL.
exit(-1);
}
else // We're in the parent process.
{
if (waitpid(pid, &ret, 0) == -1)
{
// Log an error.
}
if (!WIFEXITED(ret)) // If there was an error with the child process.
{
}
}
'WIFEXITED'用于区分'WIFSIGNALED'和'WIFSTOPPED'。在正常情况下,当孩子失败时,“WIFEXITED”为真(以非零状态退出)。你需要检查'WIFEXITED'和'WEXITSTATUS'。 –