Added comma
[unix-history] / usr / src / lib / libc / sys / execve.2
CommitLineData
2fe0358e
KM
1.\" Copyright (c) 1980 Regents of the University of California.
2.\" All rights reserved. The Berkeley software License Agreement
3.\" specifies the terms and conditions for redistribution.
4.\"
b5984ffe 5.\" @(#)execve.2 6.2 (Berkeley) %G%
2fe0358e 6.\"
547837f0 7.TH EXECVE 2 ""
2fe0358e
KM
8.UC 4
9.SH NAME
34aad5a6 10execve \- execute a file
2fe0358e 11.SH SYNOPSIS
34aad5a6
KM
12.ft B
13execve(name, argv, envp)
14.br
15char *name, *argv[], *envp[];
2fe0358e
KM
16.fi
17.SH DESCRIPTION
34aad5a6
KM
18.I Execve
19transforms the calling process into a new process.
20The new process is constructed from an ordinary file
21called the \fInew process file\fP.
22This file is either an executable object file,
23or a file of data for an interpreter.
24An executable object file consists of an identifying header,
25followed by pages of data representing the initial program (text)
26and initialized data pages. Additional pages may be specified
27by the header to be initialize with zero data. See
28.IR a.out (5).
29.PP
30An interpreter file begins with a line of the form ``#! \fIinterpreter\fP'';
31When an interpreter file is
32.IR execve\| 'd,
33the system \fIexecve\fP\|'s the specified \fIinterpreter\fP, giving
34it the name of the originally exec'd file as an argument,
35shifting over the rest of the original arguments.
36.PP
37There can be no return from a successful \fIexecve\fP because the calling
2fe0358e 38core image is lost.
34aad5a6
KM
39This is the mechanism whereby different process images become active.
40.PP
41The argument \fIargv\fP is an array of character pointers
42to null-terminated character strings. These strings constitute
43the argument list to be made available to the new
44process. By convention, at least one argument must be present in
45this array, and the first element of this array should be
46the name of the executed program (i.e. the last component of \fIname\fP).
47.PP
48The argument \fIenvp\fP is also an array of character pointers
49to null-terminated strings. These strings pass information to the
50new process which are not directly arguments to the command, see
51.IR environ (7).
52.PP
53Descriptors open in the calling process remain open in
54the new process, except for those for which the close-on-exec
55flag is set; see
56.IR close (2).
57Descriptors which remain open are unaffected by
58.IR execve .
59.PP
60Ignored signals remain ignored across an
61.IR execve ,
62but signals that are caught are reset to their default values.
63The signal stack is reset to be undefined; see
64.IR sigvec (2)
65for more information.
66.PP
67Each process has
2fe0358e 68.I real
34aad5a6 69user and group IDs and a
2fe0358e 70.I effective
34aad5a6
KM
71user and group IDs. The
72.I real
73ID identifies the person using the system; the
74.I effective
75ID determines his access privileges.
76.I Execve
2fe0358e 77changes the effective user and group ID to
34aad5a6
KM
78the owner of the executed file if the file has the \*(lqset-user-ID\*(rq
79or \*(lqset-group-ID\*(rq modes. The
80.I real
2fe0358e
KM
81user ID is not affected.
82.PP
34aad5a6
KM
83The new process also inherits the following attributes from
84the calling process:
2fe0358e 85.PP
34aad5a6
KM
86.in +5n
87.nf
88.ta +2i
89process ID see \fIgetpid\fP\|(2)
90parent process ID see \fIgetppid\fP\|(2)
91process group ID see \fIgetpgrp\fP\|(2)
92access groups see \fIgetgroups\fP\|(2)
93working directory see \fIchdir\fP\|(2)
94root directory see \fIchroot\fP\|(2)
95control terminal see \fItty\fP\|(4)
96resource usages see \fIgetrusage\fP\|(2)
97interval timers see \fIgetitimer\fP\|(2)
98resource limits see \fIgetrlimit\fP\|(2)
99file mode mask see \fIumask\fP\|(2)
100signal mask see \fIsigvec\fP\|(2)
101.in -5n
102.fi
2fe0358e 103.PP
34aad5a6 104When the executed program begins, it is called as follows:
2fe0358e 105.PP
34aad5a6 106.DT
2fe0358e
KM
107.nf
108 main(argc, argv, envp)
109 int argc;
110 char **argv, **envp;
111.fi
112.PP
113where
34aad5a6
KM
114.I argc
115is the number of elements in \fIargv\fP
116(the ``arg count'')
2fe0358e 117and
34aad5a6
KM
118.I argv
119is the array of character pointers
2fe0358e 120to the arguments themselves.
2fe0358e
KM
121.PP
122.I Envp
123is a pointer to an array of strings that constitute
124the
125.I environment
126of the process.
34aad5a6 127A pointer to this array is also stored in the global variable ``environ''.
2fe0358e
KM
128Each string consists of a name, an \*(lq=\*(rq, and a null-terminated value.
129The array of pointers is terminated by a null pointer.
130The shell
131.IR sh (1)
132passes an environment entry for each global shell variable
133defined when the program is called.
134See
34aad5a6 135.IR environ (7)
2fe0358e
KM
136for some conventionally
137used names.
34aad5a6 138.SH "RETURN VALUE
2fe0358e 139If
34aad5a6
KM
140.I execve
141returns to the calling process an error has occurred; the
142return value will be \-1 and the global variable
143.I errno
144will contain an error code.
145.SH ERRORS
146.I Execve
147will fail and return to the calling process if one or more
148of the following are true:
149.TP 15
b5984ffe
KM
150[ENOTDIR]
151A component of the path prefix is not a directory.
152.TP 15
153[EINVAL]
154The pathname contains a character with the high-order bit set.
155.TP 15
156[ENAMETOOLONG]
157A component of a pathname exceeded 255 characters,
158or an entire path name exceeded 1023 characters.
159.TP 15
34aad5a6 160[ENOENT]
b5984ffe 161The new process file does not exist.
34aad5a6 162.TP 15
b5984ffe
KM
163[ELOOP]
164Too many symbolic links were encountered in translating the pathname.
34aad5a6
KM
165.TP 15
166[EACCES]
b5984ffe 167Search permission is denied for a component of the path prefix.
34aad5a6
KM
168.TP 15
169[EACCES]
170The new process file is not an ordinary file.
171.TP 15
172[EACCES]
173The new process file mode denies execute permission.
174.TP 15
175[ENOEXEC]
176The new process file has the appropriate access
177permission, but has an invalid magic number in its header.
178.TP 15
179[ETXTBSY]
180The new process file is a pure procedure (shared text)
181file that is currently open for writing or reading by some process.
182.TP 15
183[ENOMEM]
184The new process requires more virtual memory than
185is allowed by the imposed maximum
186.RI ( getrlimit (2)).
187.TP 15
188[E2BIG]
189The number of bytes in the new process's argument list
190is larger than the system-imposed limit of {ARG_MAX} bytes.
191.TP 15
192[EFAULT]
193The new process file is not as long as indicated by
194the size values in its header.
195.TP 15
196[EFAULT]
197\fIPath\fP\|, \fIargv\fP\|, or \fIenvp\fP point
198to an illegal address.
199.SH CAVEATS
200If a program is
201.I setuid
202to a non-super-user, but is executed when
203the real \fIuid\fP is ``root'', then the program has the powers
204of a super-user as well.
205.SH "SEE ALSO"
206exit(2), fork(2), execl(3), environ(7)