0% found this document useful (0 votes)
209 views2 pages

Printing - Execl, Execle, Execlp, Execlpe, Execv, Execve, Execvp, Execvpe

The exec... family of functions load and execute child processes in the current process's memory space, replacing the current process. These functions take a path and arguments to the new process and search for the executable to load. If successful, the functions do not return as the current process is replaced by the child. They set errno on error.

Uploaded by

Azhar Laskar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
209 views2 pages

Printing - Execl, Execle, Execlp, Execlpe, Execv, Execve, Execvp, Execvpe

The exec... family of functions load and execute child processes in the current process's memory space, replacing the current process. These functions take a path and arguments to the new process and search for the executable to load. If successful, the functions do not return as the current process is replaced by the child. They set errno on error.

Uploaded by

Azhar Laskar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

execl, execle, execlp, execlpe, execv, execve, execvp, execvpe

See also Examples Portability

Syntax
#include <process.h>
int execl(char *path, char *arg0 *arg1, ..., *argn, NULL);
int _wexecl(wchar_t *path, wchar_t *arg0 *arg1, ..., *argn, NULL);
int execle(char *path, char *arg0, *arg1, ..., *argn, NULL, char **env);
int _wexecle(wchar_t *path, wchar_t *arg0, *arg1, ..., *argn, NULL,
wchar_t **env);

int execlp(char *path, char *arg0,*arg1, ..., *argn, NULL);


int _wexeclp(wchar_t *path, wchar_t *arg0,*arg1, ..., *argn, NULL);
int execlpe(char *path, char *arg0, *arg1, ..., *argn, NULL, char **env);
int _wexeclpe(wchar_t *path, wchar_t *arg0, *arg1, ..., *argn, NULL,
wchar_t **env);

int execv(char *path, char *argv[]);


int _wexecv(wchar_t *path, wchar_t *argv[]);
int execve(char *path, char *argv[], char **env);
int _wexecve(wchar_t *path, wchar_t *argv[], wchar_t **env);

int execvp(char *path, char *argv[]);


int _wexecvp(wchar_t *path, wchar_t *argv[]);
int execvpe(char *path, char *argv[], char **env);
int _wexecvpe(wchar_t *path, wchar_t *argv[], wchar_t **env);
Description
Loads and runs other programs.
The functions in the exec... family load and run (execute) other programs, known as child
processes. When an exec... call succeeds, the child process overlays the parent process. There
must be sufficient memory available for loading and executing the child process.
path is the file name of the called child process. The exec... functions search for path using the
standard search algorithm:
If no explicit extension is given, the functions search for the file as given. If the file is not found,
they add .EXE and search again. If not found, they add .COM and search again. If found, the
command processor, COMSPEC (Windows) or COMMAND.COM (DOS), is used to run the
batch file.
If an explicit extension or a period is given, the functions search for the file exactly as given.
The suffixes l, v, p, and e added to the exec... "family name" specify that the named function
operates with certain capabilities.
l specifies that the argument pointers (arg0, arg1, ..., argn) are passed as separate arguments.
Typically, the l suffix is used when you know in advance the number of arguments to be
passed.
v specifies that the argument pointers (argv[0] ..., arg[n]) are passed as an array of pointers.
Typically, the v suffix is used when a variable number of arguments is to be passed.
p specifies that the function searches for the file in those directories specified by the PATH
environment variable (without the p suffix, the function searches only the current working
directory). If the path parameter does not contain an explicit directory, the function searches
first the current directory, then the directories set with the PATH environment variable.
e specifies that the argument env can be passed to the child process, letting you alter the
environment for the child process. Without the e suffix, child processes inherit the
environment of the parent process.
Each function in the exec... family must have one of the two argument-specifying suffixes (either l
or v). The path search and environment inheritance suffixes (p and e) are optional; for example:
execl is an exec... function that takes separate arguments, searches only the root or current
directory for the child, and passes on the parent's environment to the child.
execvpe is an exec... function that takes an array of argument pointers, incorporates PATH in its
search for the child process, and accepts the env argument for altering the child's environment.
The exec... functions must pass at least one argument to the child process (arg0 or argv[0]); this
argument is, by convention, a copy of path. (Using a different value for this 0th argument won't
produce an error.)
path is available for the child process.
When the l suffix is used, arg0 usually points to path, and arg1, ..., argn point to character strings
that form the new list of arguments. A mandatory null following argn marks the end of the list.
When the e suffix is used, you pass a list of new environment settings through the argument env.
This environment argument is an array of character pointers. Each element points to a
null-terminated character string of the form
envvar = value
where envvar is the name of an environment variable, and value is the string value to which envvar
is set. The last element in env is null. When env is null, the child inherits the parents' environment
settings.
The combined length of arg0 + arg1 + ... + argn (or of argv[0] + argv[1] + ... + argn[n]), including
space characters that separate the arguments, must be less than 128 bytes for a 16-bit
application, or 260 bytes for Win32 application. Null terminators are not counted.
When an exec... function call is made, any open files remain open in the child process.

Return Value
If successful, the exec... functions do not return. On error, the exec... functions return -1, and the
global variable errno is set to one of the following values:
EACCES Permission denied
EMFILE Too many open files
ENOENT Path or file name not found
ENOEXEC Exec format error
ENOMEM Not enough memory

You might also like