1EXECVE(2) System Calls Manual EXECVE(2)
2
3
4
6 execve - execute a file
7
9 execve(name, argv, envp)
10 char *name, *argv[], *envp[];
11
13 Execve transforms the calling process into a new process. The new
14 process is constructed from an ordinary file called the new process
15 file. This file is either an executable object file, or a file of data
16 for an interpreter. An executable object file consists of an identify‐
17 ing header, followed by pages of data representing the initial program
18 (text) and initialized data pages. Additional pages may be specified
19 by the header to be initialized with zero data. See a.out(5).
20
21 An interpreter file begins with a line of the form ``#! interpreter''.
22 When an interpreter file is execve'd, the system execve's the specified
23 interpreter, giving it the name of the originally exec'd file as an
24 argument and shifting over the rest of the original arguments.
25
26 There can be no return from a successful execve because the calling
27 core image is lost. This is the mechanism whereby different process
28 images become active.
29
30 The argument argv is a null-terminated array of character pointers to
31 null-terminated character strings. These strings constitute the argu‐
32 ment list to be made available to the new process. By convention, at
33 least one argument must be present in this array, and the first element
34 of this array should be the name of the executed program (i.e., the
35 last component of name).
36
37 The argument envp is also a null-terminated array of character pointers
38 to null-terminated strings. These strings pass information to the new
39 process that is not directly an argument to the command (see envi‐
40 ron(7)).
41
42 Descriptors open in the calling process remain open in the new process,
43 except for those for which the close-on-exec flag is set (see
44 close(2)). Descriptors that remain open are unaffected by execve.
45
46 Ignored signals remain ignored across an execve, but signals that are
47 caught are reset to their default values. Blocked signals remain
48 blocked regardless of changes to the signal action. The signal stack
49 is reset to be undefined (see sigvec(2) for more information).
50
51 Each process has real user and group IDs and an effective user and
52 group IDs. The real ID identifies the person using the system; the
53 effective ID determines his access privileges. Execve changes the
54 effective user and group ID to the owner of the executed file if the
55 file has the “set-user-ID” or “set-group-ID” modes. The real user ID
56 is not affected.
57
58 The new process also inherits the following attributes from the calling
59 process:
60
61 process ID see getpid(2)
62 parent process ID see getppid(2)
63 process group ID see getpgrp(2)
64 access groups see getgroups(2)
65 working directory see chdir(2)
66 root directory see chroot(2)
67 control terminal see tty(4)
68 resource usages see getrusage(2)
69 interval timers see getitimer(2)
70 resource limits see getrlimit(2)
71 file mode mask see umask(2)
72 signal mask see sigvec(2), sigmask(2)
73
74 When the executed program begins, it is called as follows:
75
76 main(argc, argv, envp)
77 int argc;
78 char **argv, **envp;
79
80 where argc is the number of elements in argv (the ``arg count'') and
81 argv is the array of character pointers to the arguments themselves.
82
83 Envp is a pointer to an array of strings that constitute the environ‐
84 ment of the process. A pointer to this array is also stored in the
85 global variable ``environ''. Each string consists of a name, an “=”,
86 and a null-terminated value. The array of pointers is terminated by a
87 null pointer. The shell sh(1) passes an environment entry for each
88 global shell variable defined when the program is called. See envi‐
89 ron(7) for some conventionally used names.
90
92 If execve returns to the calling process an error has occurred; the
93 return value will be -1 and the global variable errno will contain an
94 error code.
95
97 Execve will fail and return to the calling process if one or more of
98 the following are true:
99
100 [ENOTDIR] A component of the path prefix is not a directory.
101
102 [EINVAL] The pathname contains a character with the high-order
103 bit set.
104
105 [ENAMETOOLONG] A component of a pathname exceeded 255 characters, or an
106 entire path name exceeded 1023 characters.
107
108 [ENOENT] The new process file does not exist.
109
110 [ELOOP] Too many symbolic links were encountered in translating
111 the pathname.
112
113 [EACCES] Search permission is denied for a component of the path
114 prefix.
115
116 [EACCES] The new process file is not an ordinary file.
117
118 [EACCES] The new process file mode denies execute permission.
119
120 [ENOEXEC] The new process file has the appropriate access permis‐
121 sion, but has an invalid magic number in its header.
122
123 [ETXTBSY] The new process file is a pure procedure (shared text)
124 file that is currently open for writing or reading by
125 some process.
126
127 [ENOMEM] The new process requires more virtual memory than is
128 allowed by the imposed maximum (getrlimit(2)).
129
130 [E2BIG] The number of bytes in the new process's argument list
131 is larger than the system-imposed limit. The limit in
132 the system as released is 20480 bytes (NCARGS in
133 <sys/param.h>.
134
135 [EFAULT] The new process file is not as long as indicated by the
136 size values in its header.
137
138 [EFAULT] Path, argv, or envp point to an illegal address.
139
140 [EIO] An I/O error occurred while reading from the file sys‐
141 tem.
142
144 If a program is setuid to a non-super-user, but is executed when the
145 real uid is ``root'', then the program has some of the powers of a
146 super-user as well.
147
149 exit(2), fork(2), execl(3), environ(7)
150
151
152
1534th Berkeley Distribution May 22, 1986 EXECVE(2)