EXEC(3)                        Library Routines                        EXEC(3)


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


       #include <unistd.h>

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


       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  infor-

       The (somewhat simplified) algorithm for exec is as follows:

              void exec2() {
                   return _execve();
              int exec() {
                   return fork(exec2);


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


       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.


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

GNO                             19 January 1997                        EXEC(3)

Man(1) output converted with man2html