waitpid()의 결과를 확인하여 실행 실패 여부를 확인하려고합니다. 그러나, 내가 아는 명령을 실행하여 stderr에 이슈를 쓰더라도, 아래의 수표는 결코 등록되지 않습니다. 이 코드가 잘못되었을 수 있습니까?fork/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.
{
}
}
'WIFSIGNALED'는 'WIFSIGNALED'와 'WIFSTOPPED'를 구분하는 데 사용됩니다. 정상적인 상황에서, 'WIFEXITED'는 자식이 실패 할 때 true가됩니다 (0이 아닌 상태에서 빠져 나옵니다). WIFEXITED와 WEXITSTATUS를 모두 확인해야합니다. –