System Interface Guide

exec(2)

exec(2) is the name of a family of functions that includes execl(2), execv(2), execle(2), execve(2), execlp(2), and execvp(2). All load a new process over the calling process, but with different ways of pulling together and presenting the arguments of the function. For example, execl(2) could be used like this


	execl("/usr/bin/prog2", "prog2", progarg1, progarg2, (char (*)0));

The execl argument list is:

/usr/bin/prog2

The path name of the new program file 

prog2

The name the new process gets in its argv[0]

progarg1, progarg2

The arguments to prog2 as char (*)s

(char (*)0)

A null char pointer to mark the end of the arguments 

There is no return from a successful execution of any variation of exec(2); the new process overlays the process that calls exec(2). The new process also takes over the process ID and other attributes of the old process. If a call to exec(2) fails, control is returned to the calling program with a return value of -1. You can check errno to learn why it failed.