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