1EXEC(3) Linux Programmer's Manual EXEC(3)
2
3
4
6 execl, execlp, execle, execv, execvp, execvpe - execute a file
7
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
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
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
90 All of these functions may fail and set errno for any of the errors
91 specified for execve(2).
92
94 The execvpe() function first appeared in glibc 2.11.
95
97 For an explanation of the terms used in this section, see
98 attributes(7).
99
100 ┌──────────────────────────────┬───────────────┬─────────────┐
101 │Interface │ Attribute │ Value │
102 ├──────────────────────────────┼───────────────┼─────────────┤
103 │execl(), execle(), execv() │ Thread safety │ MT-Safe │
104 ├──────────────────────────────┼───────────────┼─────────────┤
105 │execlp(), execvp(), execvpe() │ Thread safety │ MT-Safe env │
106 └──────────────────────────────┴───────────────┴─────────────┘
108 POSIX.1-2001, POSIX.1-2008.
109
110 The execvpe() function is a GNU extension.
111
113 The default search path (used when the environment does not contain the
114 variabl