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

RETURN VALUE

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

FILES

78       /bin/sh
79

ERRORS

81       All of these functions may fail and set errno for  any  of  the  errors
82       specified for the library function execve(2).
83

SEE ALSO

85       sh(1), execve(2), fork(2), ptrace(2), fexecve(3), environ(7)
86

COMPATIBILITY

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

CONFORMING TO

105       POSIX.1-2001.
106
107
108
109BSD MANPAGE                       1993-11-29                           EXEC(3)
Impressum