Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ exec(2) — Reliant UNIX 5.44c4

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

ps(1)

sh(1)

alarm(2)

exit(2)

fcntl(2)

fork(2)

getrlimit(2)

nice(2)

priocntl(2)

ptrace(2)

semop(2)

signal(2)

sigpending(2)

sigprocmask(2)

times(2)

umask(2)

atexit(3C)

lockf(3C)

system(3S)

a.out(4)

unistd(4)

environ(5)

lfs(5)

exec(2)                                                             exec(2)

NAME
     exec: execl, execv, execle, execve, execlp, execvp - execute a file

SYNOPSIS
     #include <unistd.h>

     int execl(const char *path, const char *arg0, ...,
               const char *argn, (char *)0);

     int execv(const char *path, char *const *argv);

     int execle(const char *path, const char *arg0, ...,
                const char *argn, (char *0), const char *envp[]);

     int execve(const char *path, char *const *argv,
                char *const *envp);

     int execlp(const char *file, const char *arg0, ...,
                const char *argn, (char *)0);

     int execvp(const char *file, char *const *argv);

DESCRIPTION
     exec in all its forms overlays a new process image on an old process.
     The new process image is constructed from an ordinary, executable
     file. This file is either an executable object file, or a file of data
     for an interpreter. There can be no return from a successful exec
     because the calling process image is overlaid by the new process
     image.

     An interpreter file begins with a line of the form

          #! pathname [arg]

     where pathname is the path of the interpreter, and arg is an optional
     argument. When an interpreter file is exec'd, the system execs the
     specified interpreter. The pathname specified in the interpreter file
     is passed as arg0 to the interpreter. If arg was specified in the
     interpreter file, it is passed as arg1 to the interpreter. The remain-
     ing arguments to the interpreter are arg0 through argn of the origi-
     nally exec'd file.

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

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

     where argc is the argument count, argv is an array of character poin-
     ters to the arguments themselves, and envp is an array of character
     pointers to the environment strings. As indicated, argc is at least
     one, and the first member of the array points to a string containing
     the name of the file.




Page 1                       Reliant UNIX 5.44                Printed 11/98

exec(2)                                                             exec(2)

     path points to a pathname that identifies the new process file.

     file points to the new process file. If file contains a slash charac-
     ter, this argument is used as a pathname for this file. If file does
     not contain a slash character, the path prefix for this file is
     obtained by a search of the directories passed in the PATH environment
     variable [see environ(5)]. The environment is supplied typically by
     the shell [see sh(1)].

     If the new process file is not an executable object file, execlp() and
     execvp() use the contents of that file as standard input to sh(1).

     The arguments arg0, ..., argn point to null-terminated character
     strings. These strings constitute the argument list available to the
     new process image. Minimally, arg0 must be present. It will become the
     name of the process, as displayed by the ps command. arg0 points to a
     string that is the same as path (or the last component of path). The
     list of argument strings is terminated by a (char *)0 argument.

     argv is an array of character pointers to null-terminated strings.
     These strings constitute the argument list available to the new pro-
     cess image. argv must have at least one member, and it should 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 image.
     envp is terminated by a null pointer. For execl(), execv(), execvp(),
     and execlp(), the C run-time start-off routine places a pointer to the
     environment of the calling process in the global object extern char
     **environ, and it is used to pass the environment of the calling pro-
     cess to the new process.

     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 that are being caught by the calling process are set to the
     default disposition in the new process image [see signal(2)]. Other-
     wise, the new process image inherits the signal dispositions of the
     calling process.

     After a successful call to any of the exec functions, any functions
     previously registered by the atexit() function are no longer
     registered.

     If the set-user-ID mode bit of the new process file is set [see
     chmod(2)], exec sets the effective user ID of the new process to the
     user 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


Page 2                       Reliant UNIX 5.44                Printed 11/98

exec(2)                                                             exec(2)

     ID and real group ID of the new process remain the same as those of
     the calling process. Moreover, if the set-user-ID mode bit of the new
     process file is set and the real user ID is not identical with the
     effective user ID, the file size limit will be set to the system
     default value.

     If the effective user-ID is root or superuser, the set-user-ID and
     setgroup-ID bits will be honored when the process is being controlled
     by ptrace().

     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 cal-
     ling process:

     -  nice value [see nice(2)]

     -  scheduler class and priority [see priocntl(2)]

     -  process ID

     -  parent process ID

     -  process group ID

     -  real user ID

     -  real group ID

     -  supplementary group IDs

     -  semadj values [see semop(2)]

     -  session 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)]

     -  file size limit [see ulimit(2) and getrlimit(2)]

     -  resource limits [see getrlimit(2)]



Page 3                       Reliant UNIX 5.44                Printed 11/98

exec(2)                                                             exec(2)

     -  tmsutime(), tmsstime(), tmscutime(), and tmscstime [see
        times(2)]

     -  file-locks [see fcntl(2) and lockf(3C)]

     -  controlling terminal

     -  process signal mask [see sigprocmask(2)]

     -  pending signals [see sigpending(2)]

     Upon successful completion, exec marks for update the statime field
     of the file. Should the exec succeed, the process image file is con-
     sidered to have been open()-ed. The corresponding close() is con-
     sidered to occur at a time after this open, but before process termi-
     nation or successful completion of a subsequent call to exec.

ERRORS
     The following error code descriptions are function-specific. You will
     find a general description in introprm2(2) or in errno(5).

     exec will fail and return to the calling process if one or more of the
     following apply:

     EACCES        Search permission is denied for a directory listed in
                   the new process file's path prefix.

     E2BIG         The number of bytes in the new process' argument list is
                   greater than the system-imposed limit of 20480 bytes.
                   The argument list limit is the sum of the size of the
                   argument list plus the size of the environment's
                   exported shell variables.

     EACCES        The new process file is not an ordinary file.

     EACCES        The new process file mode denies execution permission.

     EAGAIN        Total amount of system memory available when reading via
                   raw I/O is temporarily insufficient.

     EFAULT        Required hardware is not present.

     EFAULT        An a.out that was compiled with the MAU or 32B flag is
                   running on a machine without a MAU or 32B.

     EFAULT        An argument points to an illegal address.

     EINTR         A signal was caught during the exec system call.

     ELIBACC       Required shared library does not have execute permis-
                   sion.



Page 4                       Reliant UNIX 5.44                Printed 11/98

exec(2)                                                             exec(2)

     ELIBEXEC      Trying to exec a shared library directly.

     ELOOP         Too many symbolic links were encountered in translating
                   path or file.

     EMULTIHOP     Components of path require hopping to multiple remote
                   machines and the file system type does not allow it.

     ENAMETOOLONG  The length of the file or path arguments, or an element
                   of the environment variable PATH prefixed to a file,
                   exceeds PATHMAX, or the length of a file or path com-
                   ponent exceeds NAMEMAX.

     ENOENT        One or more components of the new process pathname of
                   the file do not exist or is a null pathname.

     ENOTDIR       A component of the new process path of the file prefix
                   is not a directory.

     ENOEXEC       The exec is not an execlp() or execvp(), and the new
                   process file has the appropriate access permission but
                   is not in the proper format.

     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 MAXMEM.

     ENOLINK       path points to a remote machine and the link to that
                   machine is no longer active.

RESULT
     If exec returns to the calling process, an error has occurred; the
     result is -1 and errno is set to indicate the error.

NOTES
     If you do not use the default C locale in your application, you must
     call setlocale(3C) with the appropriate arguments to set the locale of
     the new process.

SEE ALSO
     ps(1), sh(1), alarm(2), exit(2), fcntl(2), fork(2), getrlimit(2),
     nice(2), priocntl(2), ptrace(2), semop(2), signal(2), sigpending(2),
     sigprocmask(2), times(2), umask(2), atexit(3C), lockf(3C), system(3S),
     a.out(4), unistd(4), environ(5), lfs(5).








Page 5                       Reliant UNIX 5.44                Printed 11/98

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026