EXEC(2) SysV EXEC(2)
NAME
exec: environ, execl, execv, execle, execve, execlp, execvp - Execute a
file
SYNOPSIS
extern char *environ;
int execl (path, arg0, arg1, ..., argn, (char *)0)
const char *path, *arg0, *arg1, ..., *argn;
int execv (path, argv)
const char *path;
char * const argv[ ];
int execle (path, arg0, arg1, ..., argn, (char *)0, envp)
const char *path, *arg0, *arg1, ..., *argn;
char * const envp[ ];
int execve (path, argv, envp)
const char *path;
char * const argv[ ], *envp[ ];
int execlp (file, arg0, arg1, ..., argn, (char *)0)
const char *file, *arg0, *arg1, ..., *argn;
int execvp (file, argv)
const char *file;
char * const argv[ ];
DESCRIPTION
The exec functions replace the current process image with a new process
image. The new image is constructed from a regular executable file,
called a new process image file. A successful exec does not return,
because the calling process image is overlaid by the new process image.
The arguments are as follows:
path Points to a pathname identifying the new process image file.
arg Specifies an array of character pointers to null-terminated strings.
argv Specifies an array of character pointers to null-terminated strings
that represent the argument list available to the new program.
envp Specifies an array of character pointers to null-terminated strings,
constituting the environment for the new process.
file Identifies the new process image file.
If the file argument contains a slash character, the file argument
will be used as the pathname for this file. Otherwise, the path
prefix for this file is obtained by a search of the directories
passed as the environment variable PATH. If this environment
variable is not present, Domain/OS assumes a PATH of
:/bin:/usr/bin:/usr/ucb
The arguments specified by a program with an exec function is passed on
to the new process image in the corresponding main() arguments.
When a program is executed as a result of an exec call, it is entered as
a function call as follows:
int main (
int argc,
char *argv[ ] );
where argc is the argument count and argv[ ] is an array of character
pointers to the arguments themselves. In addition, the following
variable is initialized as a pointer to an array of character pointers to
the environment strings:
extern char **environ;
The argv and environ arrays are each terminated by a null pointer. The
null pointer terminating the argv array is not counted in argc.
If the process image file is not a valid executable object, the execlp
and execvp functions use the contents of that file as standard input to a
command interpreter conforming to the system(3S) function. In this case,
the command interpreter becomes the new process image.
The argv argument is an array of character pointers to null-terminated
strings. The last member of this array is a null pointer. These strings
constitute the argument list available to the new process image. The
value in argv[0] should point to a filename that is associated with the
process being started by one of the exec functions.
The const char *arg and subsequent ellipses in the execl, execlp, and
execle functions can be thought of as arg0, arg1, ..., argn. Together
they describe a list of one or more pointers to null-terminated character
strings that represent the argument list available to the new program.
The first argument must point to a filename that is associated with the
process being started by one of the exec functions, and the last argument
must be a null pointer. For the execle function, the environment is
provided by following the null pointer that will terminate the list of
arguments in the argument list to execle with an additional argument as
if it were declared as:
char * const envp[]
The envp argument to execve, and the final argument to execle, name an
array of character pointers to null-terminated strings. These strings
constitute the environment for the new process image. The environment
array is terminated with a null pointer.
For those forms not containing an envp pointer (execl, execv, execlp and
execvp) the environment for the new process image is taken from the
external variable environ in the calling process.
The number of bytes available for the new process' combined argument and
environment lists is ARG_MAX (26624). There is a restriction on the
number of bytes of argument and environment that can be handled. This
limit has been increased from roughly 10240 bytes to 26620 bytes (10-KB
to 26-KB) at SR10.4. Attempts to pass more than this much will result in
an [E2BIG] errno.
This limit is defined in the header file <sys/param.h> as NCARGS and
<limits.h> as ARG_MAX.
The required space is computed from the specified (or implicit) arguments
and Environment as follows:
For each argument: the size of that argument + 6, rounded up to a
longword boundary. For example:
((strlen(argv[i]) + 6) + 3) & (~3)
For each Environment Variable: the size of that Environment Variable
+ 1 (for a terminating null) + 4 (for a pointer to it), rounded up
to a longword boundary. For example:
((strlen(environ[i]) + 5) + 3) & (~3)
4 for a terminating Null in the Environment list.
File descriptors open in the calling process image remain open in the new
process image, except for those whose close-on-exec flag FD_CLOEXEC is
set (see the fcntl(2) function). For those file descriptors that remain
open, all attributes of the open file description, including file locks,
remain unchanged.
The state of directory streams and message catalog descriptors in the new
process image is undefined. Each mapped file and shared memory region
created with the mmap(2) function is unmapped by a successful call to any
of the exec functions, except those regions mapped with the MAP_INHERIT
option. Regions mapped with the MAP_INHERIT option remain mapped in the
new process image.
Signals set to the default action (SIG_DFL) in the calling process image
are set to the default action in the new process image. Signals set to be
ignored (SIG_IGN) by the calling process image are set to be ignored by
the new process image. Signals set to be caught by the calling process
image are set to the default action in the new process image (see the
signal.h header file).
If the set user ID mode bit of the new process image file is set (see the
chmod(2) function), the effective user ID of the new process image is set
to the owner ID of the new process image file. Similarly, if the set
group ID mode bit of the new process image file is set, the effective
group ID of the new process image is set to the group ID of the new
process image file. The real user ID, real group ID, and supplementary
group IDs of the new process image remain the same as those of the
calling process image. The effective user ID and effective group ID of
the new process image are saved (as the saved set user ID and the saved
set group ID) for use by the setuid(2) function.
The following attributes of the calling process image are unchanged after
successful completion of any of the exec functions:
+ Process ID
+ Parent process ID
+ Process group ID
+ Session membership
+ Real user ID
+ Real group ID
+ Supplementary group IDs
+ Time left until an alarm clock signal (see the alarm(2)
function)
+ Current working directory
+ Root directory
+ File mode creation mask (see the umask(2|) function)
+ Process signal mask (see the sigprocmask(2) function)
+ Pending signals (see the sigpending(2) function)
+ The tms_utime, tms_stime, tms_cutime, and tms_cstime fields of
the tms structure.
+ File size limit (see the ulimit(2) function)
+ Nice value (see the nice(2) function)
+ Value of a per-process interval timer
Upon successful completion, the exec functions mark for update the
st_atime field of the file. If an exec function failed but was able
to locate the process image file, whether the st_atime field is
marked for update is unspecified. Should the exec function succeed,
the process image file is considered to have been opened. The
corresponding close(2) is considered to occur at a time after this
open, but before process termination or successful completion of a
subsequent call to one of the exec functions.
The argv[]and envp[] arrays of pointers and the strings to which
these arrays point are not modified by a call to one of the exec
functions, except as a consequence of replacing the process image.
For programs compiled to expect XPG3, AES or POSIX standards
behavior, the execv family of system calls will no longer redefine
the SYSTYPE environment variable if there is not such an environment
variable already.
DIAGNOSTICS
If one of the exec functions returns to the calling process image, an
error has occurred; the return value is -1, and errno is set to indicate
the error.
ERRORS
If the exec functions fail, errno is set to one of the following values:
[E2BIG] The number of bytes used by the new process image's
argument list and environment list is greater than the
system-imposed limit of ARG_MAX (26624) bytes.
[EACCES] Search permission is denied for a directory listed in the
new process image file's path prefix, or the new process
image file denies execution permission, or the new process
image file is not a regular file and the implementation
does not support execution of files of its type.
[ENAMETOOLONG]
The length of the path or file arguments, or an element of
the environment variable PATH prefixed to a file, exceeds
PATH_MAX, or a pathname component is longer than NAME_MAX
and _POSIX_NO_TRUNC is in effect for that file.
[ENOENT] One or more components of the new process image file's
pathname do not exist, or the path or file argument points
to an empty string.
[ENOTDIR] A component of the new process image file's path prefix is
not a directory.
[ENOMEM] Insufficient memory is available.
[ETXTBSY] The new process image currently open for writing by some
process.
[EACCES] 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.
[EFAULT] Required hardware is not present.
[EFAULT] path, argv, or envp point to an illegal address.
[EAGAIN] Not enough memory.
[EINTR] A signal was caught during the exec system call.
If the execl, execv, execle, or execve function fails, errno is set to
the following value:
[ENOEXEC] The new process image file has the appropriate access
permission but is not in the proper format.
SEE ALSO
alarm(3), exit(2), fcntl(2), fork(2), getenv(3), nice(3), putenv(3),
sigaction(2), system(3), times(3), ulimit(3), umask(2), mmap(2),