EXEC(S) XENIX System V EXEC(S)
Name
execl, execv, execle, execve, execlp, execvp - Executes a
file.
Syntax
int execl (path, arg0, arg1, ..., argn, (char *)0)
char *path, *arg0, *arg1, ..., *argn;
int execv (path, argv)
char *path, *argv[ ];
int execle (path, arg0, arg1, ..., argn, (char *)0, envp)
char *path, *arg0, *arg1, ..., *argn, *envp[ ];
int execve (path, argv, envp);
char *path, *argv[ ], *envp[ ];
int execlp (file, arg0, arg1, ..., argn, (char *)0)
char *file, *arg0, *arg1, ..., *argn;
int execvp (file, argv)
char *file, *argv[ ];
Description
exec in all its forms transforms the calling process into a
new process. The new process is constructed from an
ordinary, executable file called the ``new process file.''
There can be no return from a successful exec because the
calling process is overlaid by the new process.
path points to a pathname that identifies the new process
file.
file points to the new process file. The path prefix for
this file is obtained by a search of the directories passed
as the environment line ``PATH ='' (see environ(M)). The
environment is supplied by the shell (see sh(C)).
arg0, arg1, ..., argn are pointers to null-terminated
character strings. These strings constitute the argument
list available to the new process. By convention, at least
arg0 must be present, and it must point to a string that is
the same as path (or its last component).
argv is an array of character pointers to null-terminated
strings. These strings constitute the argument list
available to the new process. By convention, argv must have
at least one member, and it must point to a string that is
the same as path (or its last component). argv is
terminated by a null pointer.
envp is an array of character pointers to null-terminated
Page 1 (printed 8/7/87)
EXEC(S) XENIX System V EXEC(S)
strings. These strings constitute the environment for the
new process. Envp is terminated by a null pointer.
File descriptors open in the calling process remain open in
the new process, except for those whose close-on-exec flag
is set; see fcntl(S). For those file descriptors that
remain open, the file pointer is unchanged.
Signals set to terminate the calling process will be set to
terminate the new process. Signals set to be ignored by the
calling process will be set to be ignored by the new
process. Signals set to be caught by the calling process
will be set to terminate new process; see signal(S).
If the set-user-ID mode bit of the new process file is set
(see chmod(S)), exec sets the effective user ID of the new
process to the owner ID of the new process file. Similarly,
if the set-group-ID mode bit of the new process file is set,
the effective group ID of the new process is set to the
group ID of the new process file. The real user ID and real
group ID of the new process remain the same as those of the
calling process.
Profiling is disabled for the new process; see profil(S).
The new process also inherits the following attributes from
the calling process:
Nice value (see nice(S))
Process ID
Parent process ID
Process group ID
semadj values (see semop(S))
TTY group ID (see exit(S) and signal(S))
Trace flag (see ptrace(S) request 0)
Time left until an alarm clock signal (see alarm(S))
Current working directory
Root directory
File mode creation mask (see umask(S))
File size limit (see ulimit(S))
Page 2 (printed 8/7/87)
EXEC(S) XENIX System V EXEC(S)
utime, stime, cutime, and cstime (see times(S))
From C, two interfaces are available: execl and execv.
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. The first
argument is conventionally the same as the filename (or its
last component). A 0 argument must end the argument list.
The execv version 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. As
indicated, argc is conventionally at least one and the first
member of the array points to a string containing the name
of the file.
argv is directly usable in another execv because argv[argc]
is 0.
envp is a pointer to an array of strings that constitute the
environment of the process. Each string consists of a name,
an ``='', and a null-terminated value. The array of
pointers is terminated by a null pointer. The shell sh(C)
passes an environment entry for each global shell variable
defined when the program is called. See environ(M) 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:
execle(file, arg0, arg1, . . . , argn, 0, environ);
execve(file, argv, 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.
The directory list is obtained from the environment.
Page 3 (printed 8/7/87)
EXEC(S) XENIX System V EXEC(S)
exec will fail and return to the calling process if one or
more of the following are true:
One or more components of the new process file's
pathname do not exist. [ENOENT]
A component of the new process file's path prefix is
not a directory. [ENOTDIR]
Search permission is denied for a directory listed in
the new process file's path prefix. [EACCES]
The new process file is not an ordinary file. [EACCES]
The new process file mode denies execution permission.
[EACCES]
The new process file has the appropriate access
permission, but has an invalid magic number in its
header or some other executable file format
inconsistency. [ENOEXEC]
The new process file is a pure procedure (shared text)
file that is currently open for writing by some
process. [ETXTBSY]
The new process requires more memory than is physically
available for user programs or the program would not
fit on the swap disk. [ENOMEM]
The number of bytes in the new process' argument list
is greater than the system-imposed limit of 5120 bytes.
[E2BIG]
The new process file is not as long as indicated by the
size values in its header. [EFAULT]
path, argv, or envp point to an illegal address.
[EFAULT]
Return Value
If exec returns to the calling process an error has
occurred; the return value will be -1 and errno will be set
to indicate the error.
See Also
exit(S), fork(S), proctl(S), semop(S)
Page 4 (printed 8/7/87)
EXEC(S) XENIX System V EXEC(S)
Notes
exec may still fail when physical memory is larger than the
swap disk (see ENOMEM above). However, this restriction may
be lifted using one of the following proctl(S) calls:
PRHUGEX Allows programs to be executed by this process
even if they exceed the available swap disk space.
Such programs must still fit in the available
physical memory and the caller's effective user ID
must be the super-user. Such HUGE processes are
locked in memory to prevent them from being
swapped.
PRNORMX Makes a process unable to exec HUGE programs.
This call may be executed by any user.
Page 5 (printed 8/7/87)