source: trunk/minix/man/man2/execve.2@ 11

Last change on this file since 11 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 5.8 KB
RevLine 
[9]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) 5/22/86
6.\"
7.TH EXECVE 2 "May 22, 1986"
8.UC 4
9.SH NAME
10execve \- execute a file
11.SH SYNOPSIS
12.nf
13.ft B
14#include <unistd.h>
15
16int execve(const char *\fIname\fP, char *const \fIargv\fP[], char *const \fIenvp\fP[])
17.ft R
18.fi
19.SH DESCRIPTION
20.B Execve
21transforms the calling process into a new process.
22The new process is constructed from an ordinary file
23called the \fInew process file\fP.
24This file is either an executable object file,
25or a file of data for an interpreter.
26An executable object file consists of an identifying header,
27followed by pages of data representing the initial program (text)
28and initialized data pages. Additional pages may be specified
29by the header to be initialized with zero data. See
30.BR a.out (5).
31.PP
32An interpreter file begins with a line of the form ``#! \fIinterpreter\fP''.
33When an interpreter file is
34.BR execve\| 'd,
35the system \fBexecve\fP\|'s the specified \fIinterpreter\fP, giving
36it the name of the originally exec'd file as an argument and
37shifting over the rest of the original arguments.
38.PP
39There can be no return from a successful \fBexecve\fP because the calling
40core image is lost.
41This is the mechanism whereby different process images become active.
42.PP
43The argument \fIargv\fP is a null-terminated array of character pointers
44to null-terminated character strings. These strings constitute
45the argument list to be made available to the new
46process. By convention, at least one argument must be present in
47this array, and the first element of this array should be
48the name of the executed program (i.e., the last component of \fIname\fP).
49.PP
50The argument \fIenvp\fP is also a null-terminated array of character pointers
51to null-terminated strings. These strings pass information to the
52new process that is not directly an argument to the command (see
53.BR environ (7)).
54.PP
55Descriptors open in the calling process remain open in
56the new process, except for those for which the close-on-exec
57flag is set (see
58.BR close (2)).
59Descriptors that remain open are unaffected by
60.BR execve .
61.PP
62Ignored signals remain ignored across an
63.BR execve ,
64but signals that are caught are reset to their default values.
65Blocked signals remain blocked regardless of changes to the signal action.
66The signal stack is reset to be undefined (see
67.BR sigaction (2)
68for more information).
69.PP
70Each process has
71.I real
72user and group IDs and an
73.I effective
74user and group IDs. The
75.I real
76ID identifies the person using the system; the
77.I effective
78ID determines his access privileges.
79.B Execve
80changes the effective user and group ID to
81the owner of the executed file if the file has the \*(lqset-user-ID\*(rq
82or \*(lqset-group-ID\*(rq modes. The
83.I real
84user ID is not affected.
85.PP
86The new process also inherits the following attributes from
87the calling process:
88.PP
89.in +5n
90.nf
91.ta +2i
92process ID see \fBgetpid\fP\|(2)
93parent process ID see \fBgetppid\fP\|(2)
94process group ID see \fBgetpgrp\fP\|(2)
95access groups see \fBgetgroups\fP\|(2)
96working directory see \fBchdir\fP\|(2)
97root directory see \fBchroot\fP\|(2)
98control terminal see \fBtty\fP\|(4)
99alarm timer see \fBalarm\fP\|(2)
100file mode mask see \fBumask\fP\|(2)
101signal mask see \fBsigaction\fP\|(2), \fBsigprocmask\fP\|(2)
102.in -5n
103.fi
104.PP
105When the executed program begins, it is called as follows:
106.PP
107.RS
108.ft B
109.nf
110int main(int \fIargc\fP, char *const \fIargv\fP[], char *const \fIenvp\fP[]);
111
112exit(main(\fIargc\fP, \fIargv\fP, \fIenvp\fP));
113.fi
114.ft R
115.RE
116.PP
117where
118.I argc
119is the number of elements in \fIargv\fP
120(the ``arg count'')
121and
122.I argv
123is the array of character pointers
124to the arguments themselves.
125.PP
126.I Envp
127is a pointer to an array of strings that constitute
128the
129.I environment
130of the process.
131A pointer to this array is also stored in the global variable ``environ''.
132Each string consists of a name, an \*(lq=\*(rq, and a null-terminated value.
133The array of pointers is terminated by a null pointer.
134The shell
135.BR sh (1)
136passes an environment entry for each global shell variable
137defined when the program is called.
138See
139.BR environ (7)
140for some conventionally
141used names.
142.SH "RETURN VALUE
143If
144.B execve
145returns to the calling process an error has occurred; the
146return value will be \-1 and the global variable
147.B errno
148will contain an error code.
149.SH ERRORS
150.B Execve
151will fail and return to the calling process if one or more
152of the following are true:
153.TP 15
154[ENOTDIR]
155A component of the path prefix is not a directory.
156.TP 15
157[ENAMETOOLONG]
158The path name exceeds PATH_MAX characters.
159.TP 15
160[ENOENT]
161The new process file does not exist.
162.TP 15
163[ELOOP]
164Too many symbolic links were encountered in translating the pathname.
165(Minix-vmd)
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[ENOMEM]
181The new process requires more (virtual) memory than
182is currently available.
183.TP 15
184[E2BIG]
185The number of bytes in the new process's argument list
186is larger than the system-imposed limit ARG_MAX.
187The limit in the system as released is 4096 bytes for
18816-bit MINIX 3, 16384 bytes for 32-bit Minix, and unlimited for Minix-vmd.
189.TP 15
190[EFAULT]
191\fIPath\fP\|, \fIargv\fP\|, or \fIenvp\fP point
192to an illegal address.
193.TP 15
194[EIO]
195An I/O error occurred while reading from the file system.
196.SH CAVEATS
197If a program is
198.I setuid
199to a non-super-user, but is executed when
200the real \fBuid\fP is ``root'', then the program has some of the powers
201of a super-user as well.
202.SH "SEE ALSO"
203.BR exit (2),
204.BR fork (2),
205.BR execl (3),
206.BR environ (7).
Note: See TracBrowser for help on using the repository browser.