A C source code (compiled and running Linux Centos 6.3) has the line:
execve(cmd, argv, envp);
execve
does not return, but I w
Following Rici's excellent comments and answer, I found the root cause of the problem.
The original code exits with whatever cmd
exited. I changed that to exit with 0 always. That is why the code behaves differently.
The following fix does not exhibit the error:
int status;
if (child = fork()) {
waitpid(child, &status, 0);
/*now we know execve is finished*/
if (WIFEXITED(status))
exit(WEXITSTATUS(status));
exit(1);
}
execve(cmd, argv, envp);