If I run the following code segment
pid_t p;
int status = 0;
p = fork();
if (p < 0)
report_error();
if (p == 0) // child
{
execlp("true", "true", 0);
_exit(127); // we should not get here
}
else
{
waitpid(p, &status, 0);
if(WIFEXITED(status))
printf("Exited with code %d", WEXITSTATUS(status));
}
I don't get anything printed because it seems like WIFEXITED evaluates to false. I suspect this is because "true" isn't a command per se and doesn't "exit" the child process?
Can I still rely on WEXITSTATUS(status)
even if it didn't "exit?" If I were to execlp("false", "false", 0);
instead, is it guaranteed that WEXITSTATUS(status)
is 1? It seems to be true so far, but I'd just like to confirm that this isn't just a coincidence.