1EXEC(3)                    Linux Programmer's Manual                   EXEC(3)
2
3
4

NAME

6       execl, execlp, execle, execv, execvp - execute a file
7

SYNOPSIS

9       #include <unistd.h>
10
11       extern char **environ;
12
13       int execl(const char *path, const char *arg, ...);
14       int execlp(const char *file, const char *arg, ...);
15       int execle(const char *path, const char *arg,
16                  ..., char * const envp[]);
17       int execv(const char *path, char *const argv[]);
18       int execvp(const char *file, char *const argv[]);
19

DESCRIPTION

21       The  exec() family of functions replaces the current process image with
22       a new process image.  The functions described in this manual  page  are
23       front-ends  for execve(2).  (See the manual page for execve(2) for fur‐
24       ther details about the replacement of the current process image.)
25
26       The initial argument for these functions is  the  pathname  of  a  file
27       which is to be executed.
28
29       The  const  char *arg and subsequent ellipses in the execl(), execlp(),
30       and execle() functions can be thought of  as  arg0,  arg1,  ...,  argn.
31       Together  they  describe  a list of one or more pointers to null-termi‐
32       nated strings that represent the argument list available  to  the  exe‐
33       cuted  program.  The first argument, by convention, should point to the
34       filename associated with the file being executed.  The  list  of  argu‐
35       ments  must be terminated by a NULL pointer, and, since these are vari‐
36       adic functions, this pointer must be cast (char *) NULL.
37
38       The execv() and execvp() functions provide  an  array  of  pointers  to
39       null-terminated  strings  that represent the argument list available to
40       the new program.  The first argument, by convention,  should  point  to
41       the  filename  associated  with  the file being executed.  The array of
42       pointers must be terminated by a NULL pointer.
43
44       The execle() function also specifies the environment  of  the  executed
45       process by following the NULL pointer that terminates the list of argu‐
46       ments in the argument list or the pointer to the  argv  array  with  an
47       additional  argument.  This additional argument is an array of pointers
48       to null-terminated strings and must be terminated by  a  NULL  pointer.
49       The other functions take the environment for the new process image from
50       the external variable environ in the current process.
51
52   Special semantics for execlp() and execvp()
53       The functions execlp() and execvp() will duplicate the actions  of  the
54       shell  in  searching  for  an executable file if the specified filename
55       does not contain a slash (/) character.  The search path  is  the  path
56       specified  in  the  environment by the PATH variable.  If this variable
57       isn't specified, the default path ":/bin:/usr/bin" is used.   In  addi‐
58       tion, certain errors are treated specially.
59
60       If permission is denied for a file (the attempted execve(2) failed with
61       the error EACCES), these functions will continue searching the rest  of
62       the  search path.  If no other file is found, however, they will return
63       with errno set to EACCES.
64
65       If the header of a  file  isn't  recognized  (the  attempted  execve(2)
66       failed  with the error ENOEXEC), these functions will execute the shell
67       (/bin/sh) with the path of the file as its first  argument.   (If  this
68       attempt fails, no further searching is done.)
69

RETURN VALUE

71       If  any  of  the exec() functions returns, an error will have occurred.
72       The return value is -1, and errno will be set to indicate the error.
73

ERRORS

75       All of these functions may fail and set errno for  any  of  the  errors
76       specified for the library function execve(2).
77

CONFORMING TO

79       POSIX.1-2001.
80

NOTES

82       On  some other systems the default path (used when the environment does
83       not contain the variable PATH) has the current working directory listed
84       after  /bin  and /usr/bin, as an anti-Trojan-horse measure.  Linux uses
85       here the traditional "current directory first" default path.
86
87       The behavior of execlp() and execvp() when errors occur while  attempt‐
88       ing to execute the file is historic practice, but has not traditionally
89       been documented and is not specified by the POSIX standard.   BSD  (and
90       possibly  other  systems) do an automatic sleep and retry if ETXTBSY is
91       encountered.  Linux treats it as a hard error and returns immediately.
92
93       Traditionally, the functions execlp() and execvp() ignored  all  errors
94       except  for  the  ones described above and ENOMEM and E2BIG, upon which
95       they returned.  They now return  if  any  error  other  than  the  ones
96       described above occurs.
97

SEE ALSO

99       sh(1), execve(2), fork(2), ptrace(2), fexecve(3), environ(7)
100

COLOPHON

102       This  page  is  part of release 3.25 of the Linux man-pages project.  A
103       description of the project, and information about reporting  bugs,  can
104       be found at http://www.kernel.org/doc/man-pages/.
105
106
107
108GNU                               2009-02-22                           EXEC(3)
Impressum