In my simple custom shell I\'m reading commands from the standard input and execute them with execvp(). Before this, I create a fork of the current process and I call the ex
You need to use waitpid(3) or wait(1) in the parent code to wait for the child to exit and get the error message.
The syntax is:
pid_t waitpid(pid_t pid, int *status, int options);
or
pid_t wait(int *status);
status contains the exit status. Look at the man pages to see you how to parse it.
Note that you can't do this from the child process. Once you call execvp the child process dies (for all practical purposes) and is replaced by the exec'd process. The only way you can reach exit(0) there is if execvp itself fails, but then the failure isn't because the new program ended. It's because it never ran to begin with.
Edit: the child process doesn't really die. The PID and environment remain unchanged, but the entire code and data are replaced with the exec'd process. You can count on not returning to the original child process, unless exec fails.