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[], char *const envp[]);
22
23   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
24
25       execvpe():
26           _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       layered  on  top  of execve(2).  (See the manual page for execve(2) for
32       further 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 new process image is specified via the argument
61       envp.  The envp argument is an array  of  pointers  to  null-terminated
62       strings and 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 di‐
74       rectories 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       execvpe() searches for the program using the value  of  PATH  from  the
79       caller's environment, not from the envp argument.
80
81       If  the specified filename includes a slash character, then PATH is ig‐
82       nored, and the file at the specified pathname is executed.
83
84       In addition, certain errors are treated specially.
85
86       If permission is denied for a file (the attempted execve(2) failed with
87       the  error EACCES), these functions will continue searching the rest of
88       the search path.  If no other file is found, however, they will  return
89       with errno set to EACCES.
90
91       If  the  header  of  a  file  isn't recognized (the attempted execve(2)
92       failed with the error ENOEXEC), these functions will execute the  shell
93       (/bin/sh)  with  the  path of the file as its first argument.  (If this
94       attempt fails, no further searching is done.)
95
96       All other exec() functions (which do not include  'p'  in  the  suffix)
97       take  as  their  first  argument a (relative or absolute) pathname that
98       identifies the program to be executed.
99

RETURN VALUE

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

ERRORS

105       All  of  these  functions  may fail and set errno for any of the errors
106       specified for execve(2).
107

VERSIONS

109       The execvpe() function first appeared in glibc 2.11.
110

ATTRIBUTES

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

CONFORMING TO

124       POSIX.1-2001, POSIX.1-2008.
125
126       The execvpe() function is a GNU extension.
127

NOTES

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

BUGS

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

SEE ALSO

164       sh(1),  execve(2),  execveat(2),  fork(2),  ptrace(2), fexecve(3), sys‐
165       tem(3), environ(7)
166

COLOPHON

168       This page is part of release 5.12 of the Linux  man-pages  project.   A
169       description  of  the project, information about reporting bugs, and the
170       latest    version    of    this    page,    can     be     found     at
171       https://www.kernel.org/doc/man-pages/.
172
173
174
175GNU                               2021-03-22                           EXEC(3)
Impressum