the window strings is NOT quoted at this point; other cleanups
[unix-history] / usr / src / lib / libc / gen / exec.3
CommitLineData
6db60273
KM
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.\"
2265b4e1 5.\" @(#)exec.3 6.2 (Berkeley) %G%
6db60273 6.\"
81f3396d 7.TH EXECL 3 ""
6db60273
KM
8.UC 5
9.SH NAME
2265b4e1 10execl, execv, execle, execlp, execvp, exec, execve, exect, environ \- execute a file
6db60273
KM
11.SH SYNOPSIS
12.nf
13.B execl(name, arg0, arg1, ..., argn, 0)
14.B char *name, *arg0, *arg1, ..., *argn;
15.PP
16.B execv(name, argv)
17.B char *name, *argv[];
18.PP
19.B "execle(name, arg0, arg1, ..., argn, 0, envp)"
20.B "char *name, *arg0, *arg1, ..., *argn, *envp[];"
21.PP
22.B "exect(name, argv, envp)
23.B "char *name, *argv[], *envp[];
24.PP
25.B extern char **environ;
26.fi
27.SH DESCRIPTION
28These routines provide various interfaces to the
29.I execve
30system call. Refer to
31.IR execve (2)
32for a description of their properties; only
33brief descriptions are provided here.
34.PP
35.I Exec
36in all its forms
37overlays the calling process with the named file, then
38transfers to the
39entry point of the core image of the file.
40There can be no return from a successful exec; the calling
41core image is lost.
42.PP
43The
44.I name
45argument
46is a pointer to the name of the file
47to be executed.
48The pointers
49.IR arg [ 0 ],
50.IR arg [ 1 "] ..."
51address null-terminated strings.
52Conventionally
53.IR arg [ 0 ]
54is the name of the
55file.
56.PP
57Two interfaces are available.
58.I execl
59is useful when a known file with known arguments is
60being called;
61the arguments to
62.I execl
63are the character strings
64constituting the file and the arguments;
65the first argument is conventionally
66the same as the file name (or its last component).
67A 0 argument must end the argument list.
68.PP
69The
70.I execv
71version is useful when the number of arguments is unknown
72in advance;
73the arguments to
74.I execv
75are the name of the file to be
76executed and a vector of strings containing
77the arguments.
78The last argument string must be followed
79by a 0 pointer.
80.PP
81The
82.I exect
83version is used when the executed file is to be
84manipulated with
85.IR ptrace (2).
86The program is forced to single step a single
87instruction giving the parent an opportunity to
88manipulate its state. On the VAX-11 this is done
89by setting the trace bit in the process status
90longword.
91.PP
92When a C program is executed,
93it is called as follows:
94.PP
95.nf
96 main(argc, argv, envp)
97 int argc;
98 char **argv, **envp;
99.fi
100.PP
101where
102.I argc
103is the argument count
104and
105.I argv
106is an array of character pointers
107to the arguments themselves.
108As indicated,
109.I argc
110is conventionally at least one
111and the first member of the array points to a
112string containing the name of the file.
113.PP
114.I Argv
115is directly usable in another
116.I execv
117because
118.IR argv [ argc ]
119is 0.
120.PP
121.I Envp
122is a pointer to an array of strings that constitute
123the
124.I environment
125of the process.
126Each string consists of a name, an \*(lq=\*(rq, and a null-terminated value.
127The array of pointers is terminated by a null pointer.
128The shell
129.IR sh (1)
130passes an environment entry for each global shell variable
131defined when the program is called.
132See
133.IR environ (7)
134for some conventionally
135used names.
136The C run-time start-off routine places a copy of
137.I envp
138in the global cell
139.IR environ ,
140which is used
141by
142.I execv
143and
144.I execl
145to pass the environment to any subprograms executed by the
146current program.
147.PP
148.I Execlp
149and
150.I execvp
151are called with the same arguments as
152.I execl
153and
154.IR execv ,
155but duplicate the shell's actions in searching for an executable
156file in a list of directories.
157The directory list is obtained from the environment.
158.SH FILES
159.ta \w'/bin/sh 'u
160/bin/sh shell, invoked if command file found
161by
162.I execlp
163or
164.I execvp
165.SH "SEE ALSO"
166execve(2),
167fork(2),
168environ(7),
169csh(1)
170.SH DIAGNOSTICS
171If the file cannot be found,
172if it is not executable,
173if it does not start with a valid magic number (see
174.IR a.out (5)),
175if maximum memory is exceeded,
176or if the arguments require too much space,
177a return
178constitutes the diagnostic;
179the return value is \-1.
180Even for the super-user,
181at least one of the execute-permission bits must be set for
182a file to be executed.
183.SH BUGS
184If
185.I execvp
186is called to execute a file that turns out to be a shell
187command file,
188and if it is impossible to execute the shell,
189the values of
190.I argv[0]
191and
192.I argv[\-1]
193will be modified before return.