EXEC(2)

NAME
execl, execv, execle, execve, execlp, execvp, exect, environ - execute a file

SYNOPSIS
int execl(name, arg0, arg1, ..., argn, (char *)0)
char *name, *arg0, *arg1, ..., *argn;

int execv(name, argv)
char *name, *argv[];

int execle(name, arg0, arg1, ..., argn, (char *)0, envp)
char *name, *arg0, *arg1, ..., *argn, *envp[];

int execve(name, argv, envp)
char *name, *argv[], *envp[];

int execlp(name, arg0, arg1, ..., argn, (char *)0)
char *name, *arg0, *arg1, ..., *argn;

int execvp(name, argv)
char *name, *argv[];

int exect(name, argv, envp)
char *name, *argv[], *envp[];

extern char **environ;

DESCRIPTION
Exec in all its forms overlays the calling process with the named file, then transfers to the entry point of the image of the file. There can be no return from a successful exec; the calling image is lost.

Files remain open across exec unless explicit arrangement has been made; see ioctl(2). Signals that are caught (see signal(2)) are reset to their default values. Other signals' behavior is unchanged.

Each user has a real userid and groupid and an effective userid and groupid. The real userid (groupid) identifies the person using the system; the effective userid (groupid) determines access privileges. Exec changes the effective userid and groupid to the owner of the executed file if the file has the set-userid or set-groupid modes. The real userid is not affected.

The security label (see getflab(2)) of the process is set as follows. If any arguments or environment parameters are present, or if and file descriptor numbers greater than 3 are in use, the lattice value of the process label is ascribed to them, otherwise lattice bottom. This value is ORed with the lattice value of the executed file to obtain the new lattice value for the process. If the new lattice value does not dominate the old,รย the permission mask (see umask(2)) is set to 022.

Process licenses persist. In the simplest case, the process obtains from the file the capabilities for which the process has licenses; see getplab(2). The detailed computation for process capabilities is: Nominal capabilities are determined by ANDing the file capabilities with the capabilities in the file system ceiling (see mount(2)) and then ORing with built-in minima. Nominal licenses are determined by ANDing the file licenses with the licenses in the file system ceiling and with built-in maxima. Process capabilities are set by ORing the process licenses with the nominal licenses, then ANDing with the nominal capabilities.

The builtin minimum file capabilities are all 0. The builtin maximum file licenses for T_SETPRIV and T_LOG are 0; the rest are 1.

The name argument is a pointer to the name of the file to be executed. If the first two bytes of that file are the ASCII characters then the first line of the file is taken to be ASCII and determines the name of the program to execute. The first nonblank string following in that line is substituted for name. Any second string, separated from the first by blanks or tabs, is inserted between the first two arguments (arguments 0 and 1) passed to the invoked file.

The argument pointers arg0, arg1, ... or the pointers in argv address null-terminated strings. Conventionally argument 0 is the name of the file.

Execl is useful when a known file with known arguments is being called; the arguments to execl are the character strings constituting the file and the arguments.

Execv is useful when the number of arguments is unknown in advance; the arguments to execv are the name of the file to be executed and a vector of strings containing the arguments. The last argument string must be followed by a 0 pointer.

When a C program is executed, it is called as follows:

        main(argc, argv, envp)
        int argc;
        char **argv, **envp;

where argc is the argument count and argv is an array of character pointers to the arguments themselves. Conventionally argc is at least 1 and argv[0] points to the name of the file.

Argv is directly usable in another execv because argv[argc]==0.

Envp is a pointer to an array of strings that constitute the environment of the process. Each string conventionally consists of a name, an and a null-terminated value; or a name, a pair of parentheses a value bracketed by and and a null character. The array of pointers is terminated by a null pointer. The shell sh(1) passes an environment entry for each global shell variable defined when the program is called. See environ(5) for some conventionally used names.

The C run-time start-off routine places a copy of envp in the global cell environ, which is used by execv and execl to pass the environment to any subprograms executed by the current program. The exec routines use lower-level routines as follows to pass an environment explicitly:

    execve(file, argv, environ);
    execle(file, arg0, arg1, . . . , argn, (char *)0, environ);

Execlp and execvp are called with the same arguments as execl and execv, but duplicate the shell's actions in searching for an executable file in a list of directories given in the PATH environment variable.

Exect is the same as execve, except it arranges for a stop to occur on the first instruction of the new core image for the benefit of tracers, see proc(4).

FILES

shell, invoked if command file found
    by execlp or execvp

SEE ALSO
fork(2), environ(5)

DIAGNOSTICS
E2BIG, EACCES, EFAULT, EIO, ELAB, ELOOP, ENOENT, ENOEXEC, ENOMEM, ENOTDIR, ENXIO, EROFS, ETXTBSY

BUGS
If execvp is called to execute a file that turns out to be a shell command file, and if it is impossible to execute the shell, some of the values in argv may be modified before return.
The path search of execlp and execvp does not extend to names substituted by