EXEC(2-POSIX) RISC/os Reference Manual EXEC(2-POSIX)
NAME
exec: execl, execv, execle, execve, execlp, execvp - execute
a file
SYNOPSIS
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 ordi-
nary, executable file called the "new process file". The
new process file may be either an "interpreter script" which
begins with the characters "#!", or an a.out file.
On the first line of an interpreter script, following the
"#!", is the name of a program which should be used to
interpret the contents of the file. For instance, if the
first line contains "#! /bin/sh", then the contents of the
file are executed as a shell script. An a.out file consists
of a header, a text segment, and a data segment. The data
segment contains an initialized portion and an uninitialized
portion (bss).
There can be no return from a successful exec because the
calling process is overlaid by the new process.
When a C program is executed, it is called as follows:
int main (argc, argv, envp)
int argc;
char **argv, **envp;
where argc is the argument count, argv is an array of char-
acter pointers to the arguments themselves, and envp is an
array of character pointers to the environment strings. As
indicated, argc is conventionally at least one and the first
Printed 1/15/91 Page 1
EXEC(2-POSIX) RISC/os Reference Manual EXEC(2-POSIX)
member of the array points to a string containing the name
of the file.
path points to a path name 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 variable PATH [see environ(5)]. The
environment is supplied by the shell [see sh(1) or csh(1)].
If PATH is not defined, the following directories are
searched, in order: /bin and /usr/bin.
arg0, arg1, ..., argn are pointers to null-terminated char-
acter strings. These strings constitute the argument list
available to the new process. By convention, at least arg0
must be present and 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 avail-
able 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
strings. These strings constitute the environment for the
new process. envp is terminated by a null pointer. For
execl and execv, the C run-time start-off routine places a
pointer to the environment of the calling process in the
global cell:
extern char **environ;
and it is used to pass the environment of the calling pro-
cess to the new process.
The number of bytes available for the new process' combined
argument and environment list, including NULL terminators,
is {ARG_MAX}.
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(2). For those file descriptors that
remain open, the file pointer is unchanged.
Signals set to the default action in the calling process
will be set to the default action in the new process. Sig-
nals 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 the default action in new
Page 2 Printed 1/15/91
EXEC(2-POSIX) RISC/os Reference Manual EXEC(2-POSIX)
process; see signal(2).
If the set-user-ID mode bit of the new process file is set
[see stat(5)], 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, real
group ID, and supplementary group IDs of the new process
remain the same as those of the calling process.
The shared memory segments attached to the calling process
will not be attached to the new process [see shmop(2)].
Profiling is disabled for the new process; see profil(2).
The new process also inherits the following attributes from
the calling process:
nice value [see nice(2)]
process ID
parent process ID
process group ID
session membership
semadj values [see semop(2)]
tty group ID [see exit(2) and signal(2)]
trace flag [see ptrace(2) request 0]
time left until an alarm clock signal [see alarm(2)]
current working directory
root directory
file mode creation mask [see umask(2)]
process signal mask [see sigprocmask(2)]
pending signals [see sigpending(2)]
file size limit [see ulimit(2)]
tms_utime, tms_stime, tms_cutime, and tms_cstime [see
times(2)]
file-locks [see fcntl(2)]
Upon successful completion, the exec functions mark for
update the st_atime field of the file. If the exec function
failed but was able to locate the process image file,
whether the st_atime field is marked for update is unspeci-
fied. Should the exec function succeed, the process image
file is considered to have been opened. The corresponding
close 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 function.
ERRORS
exec will fail and return to the calling process if one or
more of the following are true:
Printed 1/15/91 Page 3
EXEC(2-POSIX) RISC/os Reference Manual EXEC(2-POSIX)
[ENOENT] One or more components of the new pro-
cess path name of the file do not exist,
or path or file points to an empty
string.
[ENOTDIR] A component of the new process path of
the file prefix is not a directory.
[ENAMETOOLONG] The length of path exceeds {PATH_MAX},
or a pathname component is longer than
{NAME_MAX} while {_POSIX_NO_TRUNC} is in
effect.
[EACCES] Search permission is denied for a direc-
tory listed in the new process file's
path prefix, or the new process file is
not an ordinary file, or the new process
file mode denies execution permission.
[ENOEXEC] The exec is not an execlp or execvp, and
the new process file has the appropriate
access permission but an invalid magic
number in its header.
[ETXTBSY] The new process file is a pure procedure
(shared text) file that is currently
open for writing by some process.
[ENOMEM] The new process requires more memory
than is allowed by the system-imposed
maximum.
[E2BIG] The number of bytes in the new process's
argument list is greater than the
system-imposed limit of {ARG_MAX}.
[EFAULT] path, argv, or envp point to an illegal
address.
[EAGAIN] Not enough memory.
[ELIBACC] Required shared library does not have
execute permission.
[ELIBEXEC] Trying to exec a shared library
directly.
[EINTR] A signal was caught during the exec sys-
tem call.
[EINVAL] Trying to exec a file that calls for a
nonexistent interpreter.
Page 4 Printed 1/15/91
EXEC(2-POSIX) RISC/os Reference Manual EXEC(2-POSIX)
SEE ALSO
alarm(2), exit(2), fcntl(2), fork(2), nice(2), ptrace(2),
semop(2), signal(2), sigaction(2), times(2), ulimit(2),
umask(2), environ(5).
sh(1) in the User's Reference Manual.
DIAGNOSTICS
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.
Printed 1/15/91 Page 5