grammar
[unix-history] / usr / src / lib / libc / sys / execve.2
... / ...
CommitLineData
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.\"
5.\" @(#)execve.2 6.7 (Berkeley) %G%
6.\"
7.TH EXECVE 2 ""
8.UC 4
9.SH NAME
10execve \- execute a file
11.SH SYNOPSIS
12.ft B
13execve(name, argv, envp)
14.br
15char *name, *argv[], *envp[];
16.fi
17.SH DESCRIPTION
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 initialized 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 and
35shifting over the rest of the original arguments.
36.PP
37There can be no return from a successful \fIexecve\fP because the calling
38core image is lost.
39This is the mechanism whereby different process images become active.
40.PP
41The argument \fIargv\fP is a null-terminated 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 a null-terminated array of character pointers
49to null-terminated strings. These strings pass information to the
50new process that is not directly an argument 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 that 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.
63Blocked signals remain blocked regardless of changes to the signal action.
64The signal stack is reset to be undefined (see
65.IR sigvec (2)
66for more information).
67.PP
68Each process has
69.I real
70user and group IDs and an
71.I effective
72user and group IDs. The
73.I real
74ID identifies the person using the system; the
75.I effective
76ID determines his access privileges.
77.I Execve
78changes the effective user and group ID to
79the owner of the executed file if the file has the \*(lqset-user-ID\*(rq
80or \*(lqset-group-ID\*(rq modes. The
81.I real
82user ID is not affected.
83.PP
84The new process also inherits the following attributes from
85the calling process:
86.PP
87.in +5n
88.nf
89.ta +2i
90process ID see \fIgetpid\fP\|(2)
91parent process ID see \fIgetppid\fP\|(2)
92process group ID see \fIgetpgrp\fP\|(2)
93access groups see \fIgetgroups\fP\|(2)
94working directory see \fIchdir\fP\|(2)
95root directory see \fIchroot\fP\|(2)
96control terminal see \fItty\fP\|(4)
97resource usages see \fIgetrusage\fP\|(2)
98interval timers see \fIgetitimer\fP\|(2)
99resource limits see \fIgetrlimit\fP\|(2)
100file mode mask see \fIumask\fP\|(2)
101signal mask see \fIsigvec\fP\|(2), \fIsigmask\fP\|(2)
102.in -5n
103.fi
104.PP
105When the executed program begins, it is called as follows:
106.PP
107.DT
108.nf
109 main(argc, argv, envp)
110 int argc;
111 char **argv, **envp;
112.fi
113.PP
114where
115.I argc
116is the number of elements in \fIargv\fP
117(the ``arg count'')
118and
119.I argv
120is the array of character pointers
121to the arguments themselves.
122.PP
123.I Envp
124is a pointer to an array of strings that constitute
125the
126.I environment
127of the process.
128A pointer to this array is also stored in the global variable ``environ''.
129Each string consists of a name, an \*(lq=\*(rq, and a null-terminated value.
130The array of pointers is terminated by a null pointer.
131The shell
132.IR sh (1)
133passes an environment entry for each global shell variable
134defined when the program is called.
135See
136.IR environ (7)
137for some conventionally
138used names.
139.SH "RETURN VALUE
140If
141.I execve
142returns to the calling process an error has occurred; the
143return value will be \-1 and the global variable
144.I errno
145will contain an error code.
146.SH ERRORS
147.I Execve
148will fail and return to the calling process if one or more
149of the following are true:
150.TP 15
151[ENOTDIR]
152A component of the path prefix is not a directory.
153.TP 15
154[EINVAL]
155The pathname contains a character with the high-order bit set.
156.TP 15
157[ENAMETOOLONG]
158A component of a pathname exceeded 255 characters,
159or an entire path name exceeded 1023 characters.
160.TP 15
161[ENOENT]
162The new process file does not exist.
163.TP 15
164[ELOOP]
165Too many symbolic links were encountered in translating the pathname.
166.TP 15
167[EACCES]
168Search permission is denied for a component of the path prefix.
169.TP 15
170[EACCES]
171The new process file is not an ordinary file.
172.TP 15
173[EACCES]
174The new process file mode denies execute permission.
175.TP 15
176[ENOEXEC]
177The new process file has the appropriate access
178permission, but has an invalid magic number in its header.
179.TP 15
180[ETXTBSY]
181The new process file is a pure procedure (shared text)
182file that is currently open for writing or reading by some process.
183.TP 15
184[ENOMEM]
185The new process requires more virtual memory than
186is allowed by the imposed maximum
187.RI ( getrlimit (2)).
188.TP 15
189[E2BIG]
190The number of bytes in the new process's argument list
191is larger than the system-imposed limit.
192The limit in the system as released is 20480 bytes
193(NCARGS in
194.IR <sys/param.h> .
195.TP 15
196[EFAULT]
197The new process file is not as long as indicated by
198the size values in its header.
199.TP 15
200[EFAULT]
201\fIPath\fP\|, \fIargv\fP\|, or \fIenvp\fP point
202to an illegal address.
203.TP 15
204[EIO]
205An I/O error occurred while reading from the file system.
206.SH CAVEATS
207If a program is
208.I setuid
209to a non-super-user, but is executed when
210the real \fIuid\fP is ``root'', then the program has some of the powers
211of a super-user as well.
212.SH "SEE ALSO"
213exit(2), fork(2), execl(3), environ(7)