Right now I\'m writing a C program that must execute a child process. I\'m not doing multiple child processes simultaneously or anything, so this is fairly straightforward. I am
wait(2) gives you more than just the exit status of the child process. In order to get the real exit status, you need to use the WIFEXITED()
macro to test if the child exited normally (as opposed to abnormally via a signal etc.), and then use the WEXITSTATUS()
macro to get the real exit status:
wait(&status);
if(WIFEXITED(status))
{
if(WEXITSTATUS(status) == 0)
{
// Program succeeded
}
else
{
// Program failed but exited normally
}
}
else
{
// Program exited abnormally
}
In order for execvp(3)
to run a program in the current directory, you either need to add the current directory to your $PATH
environment (generally not a good idea), or pass it the full path, e.g. use ./myprogram
instead of just myprogram
.