1exec(2) System Calls exec(2)
2
3
4
6 exec, execl, execle, execlp, execv, execve, execvp - execute a file
7
9 #include <unistd.h>
10
11 int execl(const char *path, const char *arg0, ...
12 /* const char *argn, (char *)0 */);
13
14
15 int execv(const char *path, char *const argv[]);
16
17
18 int execle(const char *path, const char *arg0, ...
19 /* const char *argn, (char *)0,char *const envp[]*/);
20
21
22 int execve(const char *path, char *const argv[],
23 char *const envp[]);
24
25
26 int execlp(const char *file, const char *arg0, ...
27 /* const char *argn, (char *)0 */);
28
29
30 int execvp(const char *file, char *const argv[]);
31
32
34 Each of the functions in the exec family replaces the current process
35 image with a new process image. The new image is constructed from a
36 regular, executable file called the new process image file. This file
37 is either an executable object file or a file of data for an inter‐
38 preter. There is no return from a successful call to one of these func‐
39 tions because the calling process image is overlaid by the new process
40 image.
41
42
43 An interpreter file begins with a line of the form
44
45 #! pathname [arg]
46
47
48
49 where pathname is the path of the interpreter, and arg is an optional
50 argument. When an interpreter file is executed, the system invokes the
51 specified interpreter. The pathname specified in the interpreter file
52 is passed as arg0 to the interpreter. If arg was specified in the
53 interpreter file, it is passed as arg1 to the interpreter. The remain‐
54 ing arguments to the interpreter are arg0 through argn of the origi‐
55 nally exec'd file. The interpreter named by pathname must not be an
56 interpreter file.
57
58
59 When a C-language program is executed as a result of this call, it is
60 entered as a C-language function call as follows:
61
62 int main (int argc, char *argv[]);
63
64
65
66 where argc is the argument count and argv is an array of character
67 pointers to the arguments themselves. In addition, the following vari‐
68 able:
69
70 extern char **environ;
71
72
73
74 is initialized as a pointer to an array of character pointers to the
75 environment strings. The argv and environ arrays are each terminated by
76 a null pointer. The null pointer terminating the argv array is not
77 counted in argc.
78
79
80 The value of argc is non-negative, and if greater than 0, argv[0]
81 points to a string containing the name of the file. If argc is 0,
82 argv[0] is a null pointer, in which case there are no arguments. Appli‐
83 cations should verify that argc is greater than 0 or that argv[0] is
84 not a null pointer before dereferencing argv[0].
85
86
87 The arguments specified by a program with one of the exec f