Anthony Simon wrote:

> I apologize in advance if this should be obvious from the man pages but I
> still don't get it.
> 
> Could somebody explain to me the differences between the various exec
> functions?

execve is a system call, which all of the other functions are
implemented on top of. Between them, the functions provide 6 of the
possible combinations of three distinct options:

1. execle and execve take a parameter which specifies the environment
for the new program, whereas the other functions use the value of the
external variable `environ'. IOW:

        execv(path, args);

is equivalent to

        execve(path, args, environ);

2. execlp and execvp will search for the executable in the list of
directories specified by the environment variable `PATH' if the
filename doesn't contain a `/'. The other functions don't; the
filename must be the path to the executable (possibly relative to the
current directory).

3. execl, execle and execlp are variadic functions, which take any
number of arguments. The command-line arguments to the program are
terminated by a NULL pointer. execv, execve and execvp take a fixed
number of arguments, one of which is an array of pointers to the
arguments.

> An example of the usage of execve would also be much appreciated.

        char *const argv[] = {
                "/bin/sh",      /* argv[0] - the name of the program */
                "-c",
                "echo $HOME",
                NULL
        };

        char *const envp[] = {
                "HOME=/usr/bin"
        };

        execve("/bin/sh", argv, envp);

        perror("exec failed");

-- 
Glynn Clements <[EMAIL PROTECTED]>

Reply via email to