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 *path, const char *arg, ...
14                       /* (char  *) NULL */);
15       int execlp(const char *file, const char *arg, ...
16                       /* (char  *) NULL */);
17       int execle(const char *path, const char *arg, ...
18                       /*, (char *) NULL, char * const envp[] */);
19       int execv(const char *path, 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  const  char *arg and subsequent ellipses in the execl(), execlp(),
38       and execle() functions can be thought of  as  arg0,  arg1,  ...,  argn.
39       Together  they  describe  a list of one or more pointers to null-termi‐
40       nated strings that represent the argument list available  to  the  exe‐
41       cuted  program.  The first argument, by convention, should point to the
42       filename associated with the file being executed.  The  list  of  argu‐
43       ments  must be terminated by a null pointer, and, since these are vari‐
44       adic functions, this pointer must be cast (char *) NULL.
45
46       The execv(), execvp(), and execvpe()  functions  provide  an  array  of
47       pointers  to  null-terminated  strings that represent the argument list
48       available to the new  program.   The  first  argument,  by  convention,
49       should  point  to the filename associated with the file being executed.
50       The array of pointers must be terminated by a null pointer.
51
52       The execle() and execvpe() functions allow the caller  to  specify  the
53       environment  of  the  executed program via the argument envp.  The envp
54       argument is an array of pointers to null-terminated strings and must be
55       terminated by a null pointer.  The other functions take the environment
56       for the new process image from the external  variable  environ  in  the
57       calling process.
58
59   Special semantics for execlp() and execvp()
60       The  execlp(),  execvp(), and execvpe() functions duplicate the actions
61       of the shell in searching for an executable file if the specified file‐
62       name does not contain a slash (/) character.  The file is sought in the
63       colon-separated list of directory pathnames specified in the PATH envi‐
64       ronment  variable.   If  this  variable  isn't  defined,  the path list
65       defaults to a list that includes  the  directories  returned  by  conf‐
66       str(_CS_PATH)  (which  typically returns the value "/bin:/usr/bin") and
67       possibly also the current working  directory;  see  NOTES  for  further
68       details.
69
70       If  the  specified  filename  includes  a slash character, then PATH is
71       ignored, and the file at the specified pathname is executed.
72
73       In addition, certain errors are treated specially.
74
75       If permission is denied for a file (the attempted execve(2) failed with
76       the  error EACCES), these functions will continue searching the rest of
77       the search path.  If no other file is found, however, they will  return
78       with errno set to EACCES.
79
80       If  the  header  of  a  file  isn't recognized (the attempted execve(2)
81       failed with the error ENOEXEC), these functions will execute the  shell
82       (/bin/sh)  with  the  path of the file as its first argument.  (If this
83       attempt fails, no further searching is done.)
84

RETURN VALUE

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

ERRORS

90       All  of  these  functions  may fail and set errno for any of the errors
91       specified for execve(2).
92

VERSIONS

94       The execvpe() function first appeared in glibc 2.11.
95

ATTRIBUTES

97       For  an  explanation  of  the  terms  used   in   this   section,   see
98       attributes(7).
99
100       ┌──────────────────────────────┬───────────────┬─────────────┐
101Interface                     Attribute     Value       
102       ├──────────────────────────────┼───────────────┼─────────────┤
103execl(), execle(), execv()    │ Thread safety │ MT-Safe     │
104       ├──────────────────────────────┼───────────────┼─────────────┤
105execlp(), execvp(), execvpe() │ Thread safety │ MT-Safe env │
106       └──────────────────────────────┴───────────────┴─────────────┘

CONFORMING TO

108       POSIX.1-2001, POSIX.1-2008.
109
110       The execvpe() function is a GNU extension.
111

NOTES

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

BUGS

137       Before glibc 2.24, execl() and execle() employed realloc(3)  internally
138       and  were  consequently  not  async-signal-safe,  in  violation  of the
139       requirements of POSIX.1.  This was fixed in glibc 2.24.
140

SEE ALSO

142       sh(1), execve(2), execveat(2),  fork(2),  ptrace(2),  fexecve(3),  sys‐
143       tem(3), environ(7)
144

COLOPHON

146       This  page  is  part of release 4.16 of the Linux man-pages project.  A
147       description of the project, information about reporting bugs,  and  the
148       latest     version     of     this    page,    can    be    found    at
149       https://www.kernel.org/doc/man-pages/.
150
151
152
153GNU                               2017-09-15                           EXEC(3)
Impressum