#define root and root's parent fts_level values in <fts.h>
[unix-history] / usr / src / lib / libc / gen / exec.3
CommitLineData
ef0a718e
KB
1.\" Copyright (c) 1991 The Regents of the University of California.
2.\" All rights reserved.
6db60273 3.\"
ef0a718e 4.\" %sccs.include.redist.man%
6db60273 5.\"
ef0a718e
KB
6.\" @(#)exec.3 6.3 (Berkeley) %G%
7.\"
8.TH EXEC 3 ""
6db60273
KM
9.UC 5
10.SH NAME
ef0a718e 11execl, execlp, execle, exect, execv, execvp \- execute a file
6db60273
KM
12.SH SYNOPSIS
13.nf
ef0a718e
KB
14.ft B
15extern char **environ;
16.sp
17execl(const char *path, const char *arg, ...);
18execlp(const char *file, const char *arg, ...);
19execle(const char *path, const char *arg, ...,
20.ti +5
21char *const envp[]);
22exect(const char *path, char *const argv[],
23.ti +5
24char *const envp[]);
25execv(const char *path, char *const argv[]);
26execvp(const char *file, char *const argv[]);
27.ft R
6db60273
KM
28.fi
29.SH DESCRIPTION
ef0a718e
KB
30The exec family of functions replaces the current process image with a
31new process image.
32The functions described in this manual page are front-ends for the function
33.IR execve (2).
34(See the manual page for
35.I execve
36for detailed information about the replacement of the current process.)
6db60273 37.PP
ef0a718e
KB
38The initial argument for these functions is the pathname of a file which
39is to be executed.
6db60273 40.PP
ef0a718e
KB
41The ``const char *arg'' and subsequent ellipses in the
42.IR execl ,
43.IR execlp ,
44and
45.I execle
46functions can be thought of as
47.IR arg0 ,
48.IR arg1 ,
49\&...,
50.IR argn .
51Together they describe a list of one or more pointers to null-terminated
52strings that represent the argument list available to the executed program.
53The first argument, by convention, should point to the file name associated
54with the file being executed.
55The list of arguments
56.B must
57be terminated by a NULL pointer.
6db60273
KM
58.PP
59The
ef0a718e
KB
60.IR exect ,
61.IR execv ,
62and
63.I execvp
64functions provide an array of pointers to null-terminated strings that
65represent the argument list available to the new program.
66The first argument, by convention, should point to the file name associated
67with the file begin executed.
68The array of pointers
69.B must
70be terminated by a NULL pointer.
6db60273
KM
71.PP
72The
ef0a718e
KB
73.I execle
74and
6db60273 75.I exect
ef0a718e
KB
76functions also specify the environment of the executed process by following
77the NULL pointer that terminates the list of arguments in the parameter list
78or the pointer to the argv array with an additional parameter.
79This additional parameter is an array of pointers to null-terminated strings
80and
81.B must
82be terminated by a NULL pointer.
83The other functions take the environment for the new process image from the
84external variable
85.I environ
86in the current process.
6db60273 87.PP
ef0a718e 88Some of these functions have special semantics.
6db60273 89.PP
ef0a718e
KB
90The functions
91.I execlp
6db60273 92and
ef0a718e
KB
93.I execvp
94will duplicate the actions of the shell in searching for an executable file
95if the specified file name does not contain a slash (``/'') character.
96The search path is the path specified in the environment by ``PATH'' variable.
97If this variable isn't specified, the default path ``/bin:/usr/bin:'' is
98used.
99In addtion, certain errors are treated specially.
6db60273 100.PP
ef0a718e
KB
101If permission is denied for a file (the attempted
102.I execve
103returned EACCES), these functions will continue searching the rest of
104the search path.
105If no other file is found, however, they will return with
106.I errno
107set to EACCES.
6db60273 108.PP
ef0a718e
KB
109If the header of a file isn't recognized (the attempted
110.I execve
111returned ENOEXEC), these functions will execute the shell with the path of
112the file as its first argument.
113(If this attempt fails, no further searching is done.)
114.PP
115If the file is currently busy (the attempted
116.I execve
117returned ETXTBUSY), these functions will sleep for several seconds,
118periodically re-attempting to execute the file.
6db60273 119.PP
ef0a718e
KB
120The function
121.I exect
122executes a file with the program tracing facilities enabled (see
123.IR ptrace (2)).
124.SH "RETURN VALUE"
125If any of the
126.I exec
127functions returns, an error will have occurred.
128The return value is -1, and
129.I errno
130will be set to indicate the error.
131.SH ERRORS
132.IR Execl ,
133.IR execle ,
134.I execlp
6db60273
KM
135and
136.I execvp
ef0a718e
KB
137may fail and set
138.I errno
139for any of the errors specified for the library functions
140.IR execve (2)
6db60273 141and
ef0a718e
KB
142.IR malloc (3).
143.PP
144.I Exect
145and
146.I execv
147may fail and set
148.I errno
149for any of the errors specified for the library function
150.IR execve (2).
6db60273 151.SH FILES
ef0a718e
KB
152/bin/sh The shell.
153.SH "SEE ALSO"
154sh(1), execve(2), fork(2), ptrace(2), environ(7),
155.SH COMPATIBILITY
156Historically, the default path for the
6db60273 157.I execlp
ef0a718e 158and
6db60273 159.I execvp
ef0a718e
KB
160functions was ``:/bin:/usr/bin''.
161This was changed to place the current directory last to enhance system
162security.
163.PP
164The behavior of
165.I execlp
166and
167.I execvp
168when errors occur while attempting to execute the file is historic
169practice, but has not traditionally been documented and is not specified
170by the POSIX standard.
171.PP
172Traditionally, the functions
173.I execlp
174and
6db60273 175.I execvp
ef0a718e
KB
176ignored all errors except for the ones described above and ENOMEM and
177E2BIG, upon which they returned.
178They now return if any error other than the ones described above occurs.
179.SH STANDARDS
180.IR Execl ,
181.IR execv ,
182.IR execle ,
183.IR execlp
6db60273 184and
ef0a718e
KB
185.I execvp
186conform to IEEE Std 1003.1-1988 (``POSIX'').