Penguin
Annotated edit history of exec(3) version 4, including all changes. View license author blame.
Rev Author # Line
1 perry 1 !!NAME
2
4 CraigBox 3 execl, execlp, execle, execv, execvp - execute a file
1 perry 4
5 !!SYNOPSIS
6
3 JohnMcPherson 7 <pre>
1 perry 8 #include <uinstd.h>
9
2 DanielLawson 10 extern char **environ;
1 perry 11
2 DanielLawson 12 int execl( const char *__''path''__, const char *__''arg''__, ...);
13 int execlp( const char *__''file''__, const char *__''arg''__, ...);
3 JohnMcPherson 14 int execle( const char *__''path''__, const char *__''arg''__,... , char * const__ ''envp''__~[]);
15 int execv( const char *__''path''__, char *const __''argv''__~[]);
16 int execvp( const char *__''file''__, char *const __''argv''__~[]);
17 </pre>
1 perry 18
3 JohnMcPherson 19 !!DESCRIPTION
1 perry 20
4 CraigBox 21 The __exec__ family of functions replaces the current process image with a new process image. The functions described in this manual page are front-ends for the function execve(2). (See the manual page for __execve__ for detailed information about the replacement of the current process.)
1 perry 22
4 CraigBox 23 The initial argument for these functions is the pathname of a file which is to be executed.
1 perry 24
4 CraigBox 25 The ''const char *arg'' and subsequent ellipses in the __execl__, __execlp__, and __execle__ functions can be thought of as ''arg0'', ''arg1'', ..., ''argn''. Together they describe a list of one or more pointers to null-terminated strings that represent the argument list available to the executed program. The first argument, by convention, should point to the file name associated with the file being executed. The list of arguments ''must''
1 perry 26 be terminated by a __NULL__ pointer.
27
4 CraigBox 28 The __execv__ and __execvp__ functions provide an array of pointers to null-terminated strings that represent the argument list available to the new program. The first argument, by convention, should point to the file name associated with the file being executed. The array of pointers ''must'' be terminated by a __NULL__ pointer.
1 perry 29
4 CraigBox 30 The __execle__ function also specifies the environment of the executed process by following the __NULL__ pointer that terminates the list of arguments in the parameter list or the pointer to the argv array with an additional parameter. This additional parameter is an array of pointers to null-terminated strings and ''must'' be terminated by a __NULL__ pointer. The other functions take the environment for the new process image from the external variable ''environ'' in the current process.
1 perry 31
32 Some of these functions have special semantics.
33
4 CraigBox 34 The functions __execlp__ and __execvp__ will duplicate the actions of the shell in searching for an executable file if the specified file name does not contain a slash (/) character. The search path is the path specified in the environment by the __PATH__ variable. If this variable isn't specified, the default path ``:/bin:/usr/bin'' is used. In addition, certain errors are treated specially.
1 perry 35
4 CraigBox 36 If permission is denied for a file (the attempted __execve__ returned [EACCES]), these functions will continue searching the rest of the search path. If no other file is found, however, they will return with the global variable ''errno'' set to __EACCES__.
3 JohnMcPherson 37
4 CraigBox 38 If the header of a file isn't recognized (the attempted __execve__ returned [ENOEXEC]), these functions will execute the shell with the path of the file as its first argument. (If this attempt fails, no further searching is done.)
3 JohnMcPherson 39
1 perry 40 !!RETURN VALUE
41
4 CraigBox 42 If any of the __exec__ functions returns, an error will have occurred. The return value is -1, and the global variable ''errno'' will be set to indicate the error.
1 perry 43
44 !!FILES
45
4 CraigBox 46 ''/bin/sh''
1 perry 47
48 !!ERRORS
49
4 CraigBox 50 All of these functions may fail and set ''errno'' for any of the errors specified for the library function execve(2).
1 perry 51
52 !!SEE ALSO
53
4 CraigBox 54 sh(1), execve(2), fork(2), environ(5), ptrace(2)
1 perry 55
56 !!COMPATIBILITY
57
4 CraigBox 58 On some other systems the default path (used when the environment does not contain the variable __PATH__) has the current working directory listed after ''/bin'' and ''/usr/bin'', as an anti-Trojan-horse measure. Linux uses here the traditional "current directory first" default path.
1 perry 59
4 CraigBox 60 The behavior of __execlp__ and __execvp__ when errors occur while attempting to execute the file is historic practice, but has not traditionally been documented and is not specified by the [POSIX] standard. [BSD] (and possibly other systems) do an automatic sleep and retry if [ETXTBSY] is encountered. Linux treats it as a hard error and returns immediately.
3 JohnMcPherson 61
4 CraigBox 62 Traditionally, the functions __execlp__ and __execvp__ ignored all errors except for the ones described above and [ENOMEM] and [E2BIG], upon which they returned. They now return if any error other than the ones described above occurs.
3 JohnMcPherson 63
1 perry 64 !!CONFORMING TO
65
4 CraigBox 66 __execl__, __execv__, __execle__, __execlp__ and __execvp__ conform to IEEE Std1003.1-88 ([POSIX].1).
This page is a man page (or other imported legacy content). We are unable to automatically determine the license status of this page.

PHP Warning

lib/blame.php:177: Warning: Invalid argument supplied for foreach() (...repeated 13 times)