2.9BSD/usr/man/cat2/execve.2

Compare this file to the similar file:
Show the results in this format:


EXECVE(2)           UNIX Programmer's Manual            EXECVE(2)

NAME
     execve - execute a file

SYNOPSIS
     execve(name, argv, envp)
     char *name, *argv[], *envp[];

DESCRIPTION
     _E_x_e_c_v_e transforms the calling process into a new process.
     The new process is constructed from an ordinary file called
     the _n_e_w _p_r_o_c_e_s_s _f_i_l_e. This file is either an executable
     object file, or a file of data for an interpreter.  An exe-
     cutable object file consists of an identifying header, fol-
     lowed by pages of data representing the initial program
     (text) and initialized data pages.  Additional pages may be
     specified by the header to be initialized with zero data.
     See _a._o_u_t(5).

     An interpreter file begins with a line of the form ``#!
     _i_n_t_e_r_p_r_e_t_e_r''; when an interpreter file is _e_x_e_c_v_e'd, the
     system _e_x_e_c_v_e's the specified _i_n_t_e_r_p_r_e_t_e_r.

     There can be no return from a successful _e_x_e_c_v_e because the
     calling core image is lost.  This is the mechanism whereby
     different process images become active.

     The argument _a_r_g_v is an array of character pointers to
     null-terminated character strings.  These strings constitute
     the argument list to be made available to the new process.
     By convention, at least one argument must be present in this
     array, and the first element of this array should be the
     name of the executed program (i.e. the last component of
     _n_a_m_e).

     The arument _e_n_v_p is also an array of character pointers to
     null-terminated strings.  These strings pass information to
     the new process which are not directly arguments to the com-
     mand, see _e_n_v_i_r_o_n(5).

     Descriptors open in the calling process remain open in the
     new process, except for those for which the close-on-exec
     flag is set; see _i_o_c_t_l(2).  Descriptors which remain open
     are unaffected by _e_x_e_c_v_e.  Ignored/held signals remain
     ignored/held across _e_x_e_c_v_e, but signals that are caught are
     reset to their default values; see _s_i_g_n_a_l(2).

     Each process has a _r_e_a_l user ID and group ID and an _e_f_f_e_c_-
     _t_i_v_e user ID and group ID.  The real ID identifies the per-
     son using the system; the effective ID determines his access
     privileges.  _E_x_e_c_v_e changes the effective user and group ID
     to the owner of the executed file if the file has the
     ``set-user-ID'' or ``set-group-ID'' modes.  The real user ID

Printed 7/30/83                                                 1

EXECVE(2)           UNIX Programmer's Manual            EXECVE(2)

     is not affected.

     The new process also inheirits the following attributes from
     the calling process:

          process ID          see _g_e_t_p_i_d(2)
          parent process ID   see _g_e_t_p_i_d(2)
          process group ID    see _g_e_t_p_g_r_p(2)
          working directory   see _c_h_d_i_r(2)
          root directory      see _c_h_d_i_r(2)
          control terminal    see _t_t_y(4)
          file mode mask      see _u_m_a_s_k(2)

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

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

     where _a_r_g_c is the number of elements in _a_r_g_v (the ``arg
     count'') and _a_r_g_v is an array of character pointers to the
     arguments themselves.

     _E_n_v_p is a pointer to an array of strings that constitute the
     _e_n_v_i_r_o_n_m_e_n_t of the process.  A pointer to this arrya is also
     stored in the global variable ``environ.'' Each string con-
     sists of a name, an =, and a null-terminated value.  The
     array of pointers is terminated by a null pointer.  The
     shell _s_h(1) passes an environment entry for each global
     shell variable defined when the program is called.  See
     _e_n_v_i_r_o_n(5) for some conventionally used names.

DIAGNOSTICS
     If _e_x_e_c_v_e returns to the calling process an error has
     occurred; the return value will be -1 and the global vari-
     able _e_r_r_n_o will receive the error code.

ERRORS
     _E_x_e_c_v_e will fail and return to the calling process if one or
     more of the following is true:

     [EINVAL]            The path name contains a non-ASCII byte.

     [ENOENT]            One or more components of the new pro-
                         cess file's path name does not exist.

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

     [EACCES]            Search permission is denied for a direc-
                         tory listed in the new process file's
                         path prefix.

Printed 7/30/83                                                 2

EXECVE(2)           UNIX Programmer's Manual            EXECVE(2)

     [EACCES]            The new process file is not a regular
                         file.

     [EACCES]            The new process file mode denies execute
                         permission.

     [ENOEXEC]           The new process file has the appropriate
                         access permission but has 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 or reading by some pro-
                         cess.

     [ENOMEM]            The new process requires more memory
                         than is allowed.

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

     [EFAULT]            The new process file is not as long as
                         indicated by the size values in its
                         header.

     [EFAULT]            _N_a_m_e,_a_r_g_v,  or _e_n_v_p point to an illegal
                         address.

SEE ALSO
     csh(1), fork(2), vfork(2), environ(5)

ASSEMBLER (PDP-11)
     (exec = 11.)
     sys exec; name; argv

     (exece = 59.)
     sys exece; name; argv; envp

     _E_x_e_c is obsoleted by _e_x_e_c_e, but remains for historical rea-
     sons.

     When the called file starts execution on the PDP11, the
     stack pointer points to a word containing the number of
     arguments.  Just above this number is a list of pointers to
     the argument strings, followed by a null pointer, followed
     by the pointers to the environment strings and then another
     null pointer.  The strings themselves follow; a 0 word is
     left at the very top of memory.

       sp->    nargs
          arg0

Printed 7/30/83                                                 3

EXECVE(2)           UNIX Programmer's Manual            EXECVE(2)

          ...
          argn
          0
          env0
          ...
          envm
          0

      arg0:    <arg0\0>
          ...
      env0:    <env0\0>
          0

     On the Interdata 8/32, the stack begins at a conventional
     place (currently 0xD0000) and grows upwards.  After _e_x_e_c,
     the layout of data on the stack is as follows.

          int  0
      arg0:    byte ...
          ...
     argp0:    int  arg0
          ...
          int  0
     envp0:    int  env0
          ...
          int  0
      %2->     space     40
          int  nargs
          int  argp0
          int  envp0
      %3->

     This arrangement happens to conform well to C calling con-
     ventions.

     On a VAX-11, the stack begins at 0x7ffff000 and grows
     towards lower numbered addresses.  After _e_x_e_c, the layout of
     data on the stack is as follows.

      ap ->
      fp ->
      sp ->  .long nargs
             .long arg0
             ...
             .long argn
             .long 0
             .long env0
             ...
             .long envn
             .long 0
      arg0:  .byte "arg0\0"
             ...

Printed 7/30/83                                                 4

EXECVE(2)           UNIX Programmer's Manual            EXECVE(2)

      envn:  .byte "envn\0"
             .long 0

Printed 7/30/83                                                 5