source: trunk/minix/man/man3/execl.3@ 9

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

Minix 3.1.2a

File size: 4.5 KB
Line 
1.\" Copyright (c) 1983 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.\" @(#)execl.3 6.2 (Berkeley) 4/25/86
6.\"
7.TH EXECL 3 "April 25, 1986"
8.UC 5
9.SH NAME
10execl, execv, execle, execlp, execvp, exec, environ \- execute a file
11.SH SYNOPSIS
12.ft B
13#include <unistd.h>
14
15.in +.5i
16.ti -.5i
17int execl(const char *\fIname\fP, const char *\fIarg0\fP, ..., (char *) NULL)
18.ti -.5i
19int execv(const char *\fIname\fP, char *const \fIargv\fP[])
20.ti -.5i
21int execle(const char *\fIname\fP, const char *\fIarg0\fP, ..., (char *) NULL, char *const \fIenvp\fP[])
22.ti -.5i
23int execlp(const char *\fIname\fP, const char *\fIarg0\fP, ..., (char *) NULL)
24.ti -.5i
25int execvp(const char *\fIname\fP, char *const \fIargv\fP[])
26.in -.5i
27
28extern char *const *environ;
29.fi
30.SH DESCRIPTION
31These routines provide various interfaces to the
32.B execve
33system call. Refer to
34.BR execve (2)
35for a description of their properties; only
36brief descriptions are provided here.
37.PP
38.B Exec
39in all its forms
40overlays the calling process with the named file, then
41transfers to the
42entry point of the core image of the file.
43There can be no return from a successful exec; the calling
44core image is lost.
45.PP
46The
47.I name
48argument
49is a pointer to the name of the file
50to be executed.
51The pointers
52.IR arg [ 0 ],
53.IR arg [ 1 "] ..."
54address null-terminated strings.
55Conventionally
56.IR arg [ 0 ]
57is the name of the
58file.
59.PP
60Two interfaces are available.
61.B execl
62is useful when a known file with known arguments is
63being called;
64the arguments to
65.B execl
66are the character strings
67constituting the file and the arguments;
68the first argument is conventionally
69the same as the file name (or its last component).
70A null pointer argument must end the argument list.
71(Note that the
72.B execl*
73functions are variable argument functions. This means that the type
74of the arguments beyond
75.I arg0
76is not checked. So the null pointer requires an explicit cast to type
77.B "(char *)"
78if not of that type already.)
79.PP
80The
81.B execv
82version is useful when the number of arguments is unknown
83in advance;
84the arguments to
85.B execv
86are the name of the file to be
87executed and a vector of strings containing
88the arguments.
89The last argument string must be followed
90by a null pointer.
91.PP
92When a C program is executed,
93it is called as follows:
94.PP
95.RS
96.ft B
97.nf
98int main(int \fIargc\fP, char *const \fIargv\fP[], char *const \fIenvp\fP[]);
99
100exit(main(\fIargc\fP, \fIargv\fP, \fIenvp\fP));
101.fi
102.ft R
103.RE
104.PP
105where
106.I argc
107is the argument count
108and
109.I argv
110is an array of character pointers
111to the arguments themselves.
112As indicated,
113.I argc
114is conventionally at least one
115and the first member of the array points to a
116string containing the name of the file.
117.PP
118.I Argv
119is directly usable in another
120.B execv
121because
122.IR argv [ argc ]
123is 0.
124.PP
125.I Envp
126is a pointer to an array of strings that constitute
127the
128.I environment
129of the process.
130Each string consists of a name, an \*(lq=\*(rq, and a null-terminated value.
131The array of pointers is terminated by a null pointer.
132The shell
133.BR sh (1)
134passes an environment entry for each global shell variable
135defined when the program is called.
136See
137.BR environ (7)
138for some conventionally
139used names.
140The C run-time start-off routine places a copy of
141.I envp
142in the global cell
143.BR environ ,
144which is used
145by
146.B execv
147and
148.B execl
149to pass the environment to any subprograms executed by the
150current program.
151.PP
152.B Execlp
153and
154.B execvp
155are called with the same arguments as
156.B execl
157and
158.BR execv ,
159but duplicate the shell's actions in searching for an executable
160file in a list of directories.
161The directory list is obtained from the environment variable
162.BR PATH .
163Under standard MINIX 3, if a file is found that is executable, but does
164not have the proper executable header then it is assumed to be
165a shell script.
166.B Execlp
167and
168.B execvp
169execute
170.B /bin/sh
171to interpret the script.
172Under Minix-vmd this does not happen, a script must begin with
173.B #!
174and the full path name of the interpreter if it is to be an
175executable script.
176.SH "SEE ALSO"
177.BR execve (2),
178.BR fork (2),
179.BR environ (7),
180.BR sh (1).
181.SH DIAGNOSTICS
182If the file cannot be found,
183if it is not executable,
184if it does not start with a valid magic number (see
185.BR a.out (5)),
186if maximum memory is exceeded,
187or if the arguments require too much space,
188a return
189constitutes the diagnostic;
190the return value is \-1 and
191.B errno
192is set as for
193.BR execve .
194Even for the super-user,
195at least one of the execute-permission bits must be set for
196a file to be executed.
Note: See TracBrowser for help on using the repository browser.