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.
5 .\" @(#)execve.2 6.7 (Berkeley) 5/22/86
7 .TH EXECVE 2 "May 22, 1986"
10 execve \- execute a file
16 int execve(const char *\fIname\fP, char *const \fIargv\fP[], char *const \fIenvp\fP[])
21 transforms the calling process into a new process.
22 The new process is constructed from an ordinary file
23 called the \fInew process file\fP.
24 This file is either an executable object file,
25 or a file of data for an interpreter.
26 An executable object file consists of an identifying header,
27 followed by pages of data representing the initial program (text)
28 and initialized data pages. Additional pages may be specified
29 by the header to be initialized with zero data. See
32 An interpreter file begins with a line of the form ``#! \fIinterpreter\fP''.
33 When an interpreter file is
35 the system \fBexecve\fP\|'s the specified \fIinterpreter\fP, giving
36 it the name of the originally exec'd file as an argument and
37 shifting over the rest of the original arguments.
39 There can be no return from a successful \fBexecve\fP because the calling
41 This is the mechanism whereby different process images become active.
43 The argument \fIargv\fP is a null-terminated array of character pointers
44 to null-terminated character strings. These strings constitute
45 the argument list to be made available to the new
46 process. By convention, at least one argument must be present in
47 this array, and the first element of this array should be
48 the name of the executed program (i.e., the last component of \fIname\fP).
50 The argument \fIenvp\fP is also a null-terminated array of character pointers
51 to null-terminated strings. These strings pass information to the
52 new process that is not directly an argument to the command (see
55 Descriptors open in the calling process remain open in
56 the new process, except for those for which the close-on-exec
59 Descriptors that remain open are unaffected by
62 Ignored signals remain ignored across an
64 but signals that are caught are reset to their default values.
65 Blocked signals remain blocked regardless of changes to the signal action.
66 The signal stack is reset to be undefined (see
68 for more information).
72 user and group IDs and an
74 user and group IDs. The
76 ID identifies the person using the system; the
78 ID determines his access privileges.
80 changes the effective user and group ID to
81 the owner of the executed file if the file has the \*(lqset-user-ID\*(rq
82 or \*(lqset-group-ID\*(rq modes. The
84 user ID is not affected.
86 The new process also inherits the following attributes from
92 process ID see \fBgetpid\fP\|(2)
93 parent process ID see \fBgetppid\fP\|(2)
94 process group ID see \fBgetpgrp\fP\|(2)
95 access groups see \fBgetgroups\fP\|(2)
96 working directory see \fBchdir\fP\|(2)
97 root directory see \fBchroot\fP\|(2)
98 control terminal see \fBtty\fP\|(4)
99 alarm timer see \fBalarm\fP\|(2)
100 file mode mask see \fBumask\fP\|(2)
101 signal mask see \fBsigaction\fP\|(2), \fBsigprocmask\fP\|(2)
105 When the executed program begins, it is called as follows:
110 int main(int \fIargc\fP, char *const \fIargv\fP[], char *const \fIenvp\fP[]);
112 exit(main(\fIargc\fP, \fIargv\fP, \fIenvp\fP));
119 is the number of elements in \fIargv\fP
123 is the array of character pointers
124 to the arguments themselves.
127 is a pointer to an array of strings that constitute
131 A pointer to this array is also stored in the global variable ``environ''.
132 Each string consists of a name, an \*(lq=\*(rq, and a null-terminated value.
133 The array of pointers is terminated by a null pointer.
136 passes an environment entry for each global shell variable
137 defined when the program is called.
140 for some conventionally
145 returns to the calling process an error has occurred; the
146 return value will be \-1 and the global variable
148 will contain an error code.
151 will fail and return to the calling process if one or more
152 of the following are true:
155 A component of the path prefix is not a directory.
158 The path name exceeds PATH_MAX characters.
161 The new process file does not exist.
164 Too many symbolic links were encountered in translating the pathname.
168 Search permission is denied for a component of the path prefix.
171 The new process file is not an ordinary file.
174 The new process file mode denies execute permission.
177 The new process file has the appropriate access
178 permission, but has an invalid magic number in its header.
181 The new process requires more (virtual) memory than
182 is currently available.
185 The number of bytes in the new process's argument list
186 is larger than the system-imposed limit ARG_MAX.
187 The limit in the system as released is 4096 bytes for
188 16-bit MINIX 3, 16384 bytes for 32-bit Minix, and unlimited for Minix-vmd.
191 \fIPath\fP\|, \fIargv\fP\|, or \fIenvp\fP point
192 to an illegal address.
195 An I/O error occurred while reading from the file system.
199 to a non-super-user, but is executed when
200 the real \fBuid\fP is ``root'', then the program has some of the powers
201 of a super-user as well.