EXEC(3)

NAME
exec - load an executable file and launch as a new process

SYNOPSIS
#include <unistd.h>

int exec(const char *pathname, const char *cmdline);

DESCRIPTION
This call is provided only for backward compatibility and should be avoided. New programs should use the execve(2) family of calls, the system(3) routine, or the EXECUTE shell call.

exec is an alternative method for launching a new process under GNO. It is a combination of the fork(2) and _execve(2) system calls, and is in fact written in terms of them. The difference between exec and _execve is that exec returns in all cases; it is a simplified interface for those who don't need to affect process information before a new executable begins (such as process group IDs or I/O redirection information).

The (somewhat simplified) algorithm for exec is as follows:
    void exec2() {
    	return _execve();
    }
    int exec() {
    	return fork(exec2);
    }

RETURN VALUE
exec returns the process ID of the child, or -1 (and setting errno) if an error occurs in either the fork or _execve call.

BUGS
See the BUGS section in the execve(2) man page.

If an error occurs in the _execve phase of this call, it can only be detected with the wait(2) system call; it will get the return code of the process, which will be -1 if the _execve fails.

SEE ALSO
execve(2), fork(2), wait(2), execl(3), system(3).