Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ exec(S) — OpenDesktop Software Development System 3.0.0

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

a.out(FP)

alarm(S)

environ(M)

exit(S)

fcntl(S)

fork(S)

lockf(S)

nice(S)

ptrace(S)

semop(S)

sh(C)

signal(S)

sigset(S)

times(S)

ulimit(S)

umask(S)


 exec(S)                        6 January 1993                        exec(S)


 Name

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

 Syntax


    cc  . . .  -lc


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

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

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

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

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

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


 Description

    The exec system call in all its forms transforms the calling process into
    a new process.  The new process is constructed from an ordinary, execut-
    able file.  Executable files consist of a header (see a.out(FP)), 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 pro-
    cess.

    Executables created by C programs always use the function main as their
    entry point.  The prototype for main is (arguments are optional):

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


    where argc is the argument count, argv is an array of character 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 member of the array points to a string contain-
    ing the name of the file.

    The path argument points to a path name that identifies the new process
    file.

    The file argument 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 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 ter-
    minated 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 ter-
    minated 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 process to the new
    process.

    File descriptors open in the calling process remain open in the new pro-
    cess, 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 are set to terminate the new
    process.  Signals set to be ignored by the calling process are set to be
    ignored by the new process.  Signals set to be caught by the calling pro-
    cess are set to terminate the new process; see signal(S).

    For signals set by sigset, exec ensures that the new process has the same
    system signal action for each signal type whose action is SIGDFL,
    SIGIGN, or SIGHOLD as the calling process. However, if the action is to
    catch the signal, then the action is reset to SIGDFL, and any pending
    signal for this type is held.

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

    The shared memory segments attached to the calling process are not
    attached to the new process; see shmop(S).

    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)

    +    utime, stime, cutime, and cstime; see times(S)

    +    file-locks; see fcntl(S) and lockf(S)

    The exec system call fails and returns to the calling process if one or
    more of the following is true:

    [E2BIG]        The number of bytes in the new process's argument list is
                   greater than the system-imposed limit of 5120 bytes.

    [EACCES]


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

                   +  The new process file is not an ordinary file.

                   +  The new process file mode denies execution permission.

    [EAGAIN]       Not enough memory.

    [EFAULT]


                   +  Required hardware is not present.

                   +  path, argv, or envp point to an illegal address.

    [EINTR]        A signal was caught during the exec system call.

    [ELIBACC]      Required shared library does not have execute permission.

    [ELIBEXEC]     Trying to exec a shared library directly.

    [EMULTIHOP]    Components of path require hopping to multiple remote ma-
                   chines.

    [ENOENT]       One or more components of the new process path name of the
                   file do not exist.

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

    [ENOLINK]      path points to a remote machine and the link to that ma-
                   chine is no longer active.

    [ENOMEM]       The new process requires more memory than is allowed by
                   the system-imposed maximum MAXMEM.

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

    [ETXTBSY]      The new process file is a pure procedure (shared text)
                   file that is currently open for writing by some process.


 Notes

    Security services provided by the operating system provide the following:

    +  Executing a setuid/setgid file without a valid login UID fails.

    +  The login UID is inherited from the parent process.


 See also

    a.out(FP), alarm(S), environ(M), exit(S), fcntl(S), fork(S), lockf(S),
    nice(S), ptrace(S), semop(S), sh(C), signal(S), sigset(S), times(S),
    ulimit(S), umask(S)

 Diagnostics

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

 Standards conformance

    execl, execle, execlp, execv, execve and execvp are conformant with:
    AT&T SVID Issue 2;
    X/Open Portability Guide, Issue 3, 1989;
    IEEE POSIX Std 1003.1-1990 System Application Program Interface (API) [C
    Language] (ISO/IEC 9945-1);
    and NIST FIPS 151-1.


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