1EXEC(3)                    Linux Programmer's Manual                   EXEC(3)
2
3
4

NAME

6       execl, execlp, execle, execv, execvp, execvpe - execute a file
7

SYNOPSIS

9       #include <unistd.h>
10
11       extern char **environ;
12
13       int execl(const char *pathname, const char *arg, ...
14                       /* (char  *) NULL */);
15       int execlp(const char *file, const char *arg, ...
16                       /* (char  *) NULL */);
17       int execle(const char *pathname, const char *arg, ...
18                       /*, (char *) NULL, char * const envp[] */);
19       int execv(const char *pathname, char *const argv[]);
20       int execvp(const char *file, char *const argv[]);
21       int execvpe(const char *file, char *const argv[],
22                       char *const envp[]);
23
24   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
25
26       execvpe(): _GNU_SOURCE
27

DESCRIPTION

29       The  exec() family of functions replaces the current process image with
30       a new process image.  The functions described in this manual  page  are
31       front-ends  for execve(2).  (See the manual page for execve(2) for fur‐
32       ther details about the replacement of the current process image.)
33
34       The initial argument for these functions is the name of a file that  is
35       to be executed.
36
37       The  functions can be grouped based on the letters following the "exec"
38       prefix.
39
40   l - execl(), execlp(), execle()
41       The const char *arg and subsequent ellipses can be thought of as  arg0,
42       arg1, ..., argn.  Together they describe a list of one or more pointers
43       to null-terminated strings that represent the argument  list  available
44       to  the  executed  program.   The first argument, by convention, should
45       point to the filename associated with the  file  being  executed.   The
46       list  of  arguments  must  be  terminated by a null pointer, and, since
47       these are variadic functions, this pointer must be cast (char *) NULL.
48
49       By contrast with the 'l' functions, the 'v' functions  (below)  specify
50       the command-line arguments of the executed program as a vector.
51
52   v - execv(), execvp(), execvpe()
53       The  char *const argv[] argument is an array of pointers to null-termi‐
54       nated strings that represent the argument list  available  to  the  new
55       program.   The first argument, by convention, should point to the file‐
56       name associated with the file being executed.  The  array  of  pointers
57       must be terminated by a null pointer.
58
59   e - execle(), execvpe()
60       The  environment of the caller is specified via the argument envp.  The
61       envp argument is an array of pointers to  null-terminated  strings  and
62       must be terminated by a null pointer.
63
64       All  other  exec()  functions  (which do not include 'e' in the suffix)
65       take the environment for the new process image from the external  vari‐
66       able environ in the calling process.
67
68   p - execlp(), execvp(), execvpe()
69       These  functions duplicate the actions of the shell in searching for an
70       executable file if the specified filename does not contain a slash  (/)
71       character.  The file is sought in the colon-separated list of directory
72       pathnames specified in the PATH environment variable.  If this variable
73       isn't  defined,  the  path  list  defaults  to a list that includes the
74       directories returned by confstr(_CS_PATH) (which typically returns  the
75       value "/bin:/usr/bin") and possibly also the current working directory;
76       see NOTES for further details.
77
78       If the specified filename includes a  slash  character,  then  PATH  is
79       ignored, and the file at the specified pathname is executed.
80
81       In addition, certain errors are treated specially.
82
83       If permission is denied for a file (the attempted execve(2) failed with
84       the error EACCES), these functions will continue searching the rest  of
85       the  search path.  If no other file is found, however, they will return
86       with errno set to EACCES.
87
88       If the header of a  file  isn't  recognized  (the  attempted  execve(2)
89       failed  with the error ENOEXEC), these functions will execute the shell
90       (/bin/sh) with the path of the file as its first  argument.   (If  this
91       attempt fails, no further searching is done.)
92
93       All  other  exec()  functions  (which do not include 'p' in the suffix)
94       take as their first argument a (relative  or  absolute)  pathname  that
95       identifies the program to be executed.
96

RETURN VALUE

98       The  exec() functions return only if an error has occurred.  The return
99       value is -1, and errno is set to indicate the error.
100

ERRORS

102       All of these functions may fail and set errno for  any  of  the  errors
103       specified for execve(2).
104

VERSIONS

106       The execvpe() function first appeared in glibc 2.11.
107

ATTRIBUTES

109       For   an   explanation   of   the  terms  used  in  this  section,  see
110       attributes(7).
111
112       ┌──────────────────────────────┬───────────────┬─────────────┐
113Interface                     Attribute     Value       
114       ├──────────────────────────────┼───────────────┼─────────────┤
115execl(), execle(), execv()    │ Thread safety │ MT-Safe     │
116       ├──────────────────────────────┼───────────────┼─────────────┤
117execlp(), execvp(), execvpe() │ Thread safety │ MT-Safe env │
118       └──────────────────────────────┴───────────────┴─────────────┘

CONFORMING TO

120       POSIX.1-2001, POSIX.1-2008.
121
122       The execvpe() function is a GNU extension.
123

NOTES

125       The default search path (used when the environment does not contain the
126       variable  PATH)  shows  some  variation  across  systems.  It generally
127       includes /bin and /usr/bin (in that order) and  may  also  include  the
128       current  working directory.  On some other systems, the current working
129       is included after /bin and /usr/bin, as an  anti-Trojan-horse  measure.
130       The  glibc  implementation  long followed the traditional default where
131       the current working directory is included at the start  of  the  search
132       path.   However,  some code refactoring during the development of glibc
133       2.24 caused the current working directory to be dropped altogether from
134       the default search path.  This accidental behavior change is considered
135       mildly beneficial, and won't be reverted.
136
137       The behavior of execlp() and execvp() when errors occur while  attempt‐
138       ing to execute the file is historic practice, but has not traditionally
139       been documented and is not specified by the POSIX standard.   BSD  (and
140       possibly  other  systems) do an automatic sleep and retry if ETXTBSY is
141       encountered.  Linux treats it as a hard error and returns immediately.
142
143       Traditionally, the functions execlp() and execvp() ignored  all  errors
144       except  for  the  ones described above and ENOMEM and E2BIG, upon which
145       they returned.  They now return  if  any  error  other  than  the  ones
146       described above occurs.
147

BUGS

149       Before  glibc 2.24, execl() and execle() employed realloc(3) internally
150       and were  consequently  not  async-signal-safe,  in  violation  of  the
151       requirements of POSIX.1.  This was fixed in glibc 2.24.
152
153   Architecture-specific details
154       On  sparc and sparc64, execv() is provided as a system call by the ker‐
155       nel (with the prototype shown  above)  for  compatibility  with  SunOS.
156       This  function is not employed by the execv() wrapper function on those
157       architectures.
158

SEE ALSO

160       sh(1), execve(2), execveat(2),  fork(2),  ptrace(2),  fexecve(3),  sys‐
161       tem(3), environ(7)
162

COLOPHON

164       This  page  is  part of release 5.04 of the Linux man-pages project.  A
165       description of the project, information about reporting bugs,  and  the
166       latest     version     of     this    page,    can    be    found    at
167       https://www.kernel.org/doc/man-pages/.
168
169
170
171GNU                               2019-08-02                           EXEC(3)
Impressum