A call to execve() may fail. A classic reason for this would be if the file is missing or not executable. execvp() goes around execve() to add default path searching and default processing (almost always what you want!), and therefore it adds some more failure modes, especially trying to run something with a simple name that not in the user's path. In any case, a failure is a failure, and you cannot do much when it happens, except to report that it went wrong and get the (now useless) Out Of Dodge child process. (The easiest way to report errors is to print an error message, possibly with perror() , but there are others.)
The reason you need _exit() , as opposed to the more usual exit() , is because you want to exit the child process, but do not want to run any registered cleanup code associated with the parent process. Well, many of them can be harmless, but to do something like writing farewell messages to a socket, or something would be bad, and it is often not quite obvious what was registered in atexit() . Let the parent process worry about its resources; the child basically has nothing but his stack frame!
source share