1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
|
.TH EXEC 2
.CT 2 proc_man
.SH NAME
execl, execv, execle, execve, execlp, execvp, exect, environ \(mi execute a file
.SH SYNOPSIS
.nf
.B int "execl(name, arg0, arg1, ..., argn, (char *)0)"
.B char *name, *arg0, *arg1, ..., *argn;
.PP
.B int execv(name, argv)
.B char *name, *argv[];
.PP
.B "int execle(name, arg0, arg1, ..., argn, (char *)0, envp)"
.B "char *name, *arg0, *arg1, ..., *argn, *envp[];"
.PP
.B int execve(name, argv, envp)
.B char *name, *argv[], *envp[];
.PP
.B int "execlp(name, arg0, arg1, ..., argn, (char *)0)"
.B char *name, *arg0, *arg1, ..., *argn;
.PP
.B int execvp(name, argv)
.B char *name, *argv[];
.PP
.B int exect(name, argv, envp)
.B char *name, *argv[], *envp[];
.PP
.B extern char **environ;
.fi
.SH DESCRIPTION
.I Exec
in all its forms
overlays the calling process with the named file, then
transfers to the
entry point of the image of the file.
There can be no return from a successful
.IR exec ;
the calling image is lost.
.PP
Files remain open across
.I exec
unless explicit arrangement has been made;
see
.IR ioctl (2).
Signals that are caught (see
.IR signal (2))
are reset
to their default values.
Other signals' behavior is unchanged.
.PP
Each user has a
.I real
userid and groupid and an
.I effective
userid and groupid.
The real userid (groupid)
identifies the person using the system;
the effective userid (groupid)
determines access privileges.
.I Exec
changes the effective userid and groupid to
the owner of the executed file if the file has the set-userid
or set-groupid modes.
The real userid is not affected.
.PP
The security label (see
.IR getflab (2))
of the process is set as follows.
If any arguments or environment parameters are present,
or if and file descriptor numbers greater than 3 are in use,
the lattice value of the process label
is ascribed to them, otherwise lattice bottom.
This value is ORed with the lattice value of
the executed file to obtain the new lattice value for the process.
If the new lattice value does not dominate the old,ÃÂ
the permission mask (see
.IR umask (2))
is set to 022.
.PP
Process licenses persist.
In the simplest case, the process obtains from the
file the capabilities
for which the process has licenses; see
.IR getplab (2).
The detailed computation for process capabilities is:
Nominal capabilities are determined
by ANDing the file capabilities with the
capabilities in the file system ceiling (see
.IR mount (2))
and then ORing with built-in minima.
Nominal licenses are determined by ANDing the file licenses
with the licenses in the file system
ceiling and with built-in maxima.
Process capabilities are set by ORing the
process licenses with the nominal licenses, then ANDing
with the nominal capabilities.
.PP
The builtin minimum file capabilities are all 0.
The builtin maximum file licenses for
.B T_SETPRIV
and
.B T_LOG
are 0; the rest are 1.
.B
.PP
The
.I name
argument
is a pointer to the name of the file
to be executed.
If the first two bytes of that file are the ASCII
characters
.LR #! ,
then the first line of the file is taken to be ASCII and
determines the name of the program to execute.
The first nonblank string following
.L #!
in that line is substituted for
.I name.
Any second string, separated from the first by blanks or tabs,
is inserted between
the first two arguments (arguments 0 and 1) passed to the invoked file.
.PP
The argument pointers
.I arg0, arg1, ...
or the pointers in
.I argv
address null-terminated strings.
Conventionally argument 0
is the name of the
file.
.PP
.I Execl
is useful when a known file with known arguments is
being called;
the arguments to
.I execl
are the character strings
constituting the file and the arguments.
.PP
.I Execv
is useful when the number of arguments is unknown
in advance;
the arguments to
.I execv
are the name of the file to be
executed and a vector of strings containing
the arguments.
The last argument string must be followed
by a 0
pointer.
.PP
When a C program is executed,
it is called as follows:
.IP
.EX
main(argc, argv, envp)
int argc;
char **argv, **envp;
.EE
.PP
where
.IR argc ""
is the argument count
and
.IR argv ""
is an array of character pointers
to the arguments themselves.
Conventionally
.I argc
is at least 1
and
.B argv[0]
points to
the name of the file.
.PP
.I Argv
is directly usable in another
.I execv
because
.BR argv[argc]==0 .
.PP
.I Envp
is a pointer to an array of strings that constitute
the
.I environment
of the process.
Each string conventionally consists of a name, an
.LR = ,
and a null-terminated value;
or a name, a pair of parentheses
.LR (),
a value bracketed by
.L {
and
.LR } ,
and a null character.
The array of pointers is terminated by a null pointer.
The shell
.IR sh (1)
passes an environment entry for each global shell variable
defined when the program is called.
See
.IR environ (5)
for some conventionally
used names.
.PP
The C run-time start-off routine places a copy of
.I envp
in the global cell
.I environ,
which is used
by
.I execv
and
.I execl
to pass the environment to any subprograms executed by the
current program.
The
.I exec
routines use lower-level routines as follows
to pass an environment explicitly:
.IP
.nf
\fLexecve(file, argv, environ);
execle(file, arg0, arg1, . . . , argn, (char *)0, environ);\fP
.fi
.PP
.I Execlp
and
.I execvp
are called with the same arguments as
.I execl
and
.I execv,
but duplicate the shell's actions in searching for an executable
file in a list of directories given in the
.B PATH
environment variable.
.PP
.I Exect
is the same as
.I execve,
except it arranges for a stop to occur on the first instruction
of the new core image for the benefit of tracers, see
.IR proc (4).
.SH FILES
.TF /bin/sh
.TP
.F /bin/sh
shell, invoked if command file found
by
.I execlp
or
.I execvp
.SH "SEE ALSO"
.IR fork (2),
.IR environ (5)
.SH DIAGNOSTICS
.BR E2BIG ,
.BR EACCES ,
.BR EFAULT ,
.BR EIO ,
.BR ELAB ,
.BR ELOOP ,
.BR ENOENT ,
.BR ENOEXEC ,
.BR ENOMEM ,
.BR ENOTDIR ,
.BR ENXIO ,
.BR EROFS ,
.BR ETXTBSY
.SH BUGS
If
.I execvp
is called to execute a file that turns out to be a shell
command file,
and if it is impossible to execute the shell,
some of the values in
.I argv
may be modified before return.
.br
The path search of
.I execlp
and
.I execvp
does not extend to names substituted by
.LR #! .
|