There is no exec
system call — this is usually used to refer to all the execXX
calls as a group. They all do essentially the same thing: loading a new program into the current process, and provide it with arguments and environment variables. The differences are in how the program is found, how the arguments are specified, and where the environment comes from.
-
The calls with
v
in the name take an array parameter to specify theargv[]
array of the new program. The end of the arguments is indicated by an array element containingNULL
. -
The calls with
l
in the name take the arguments of the new program as a variable-length argument list to the function itself. The end of the arguments is indicated by a(char *)NULL
argument. You should always include the type cast, becauseNULL
is allowed to be an integer constant, and default argument conversions when calling a variadic function won’t convert that to a pointer. -
The calls with
e
in the name take an extra argument (or arguments in thel
case) to provide the environment of the new program; otherwise, the program inherits the current process’s environment. This is provided in the same way as theargv
array: an array forexecve()
, separate arguments forexecle()
. -
The calls with
p
in the name search thePATH
environment variable to find the program if it doesn’t have a directory in it (i.e. it doesn’t contain a/
character). Otherwise, the program name is always treated as a path to the executable. -
FreeBSD 5.2 added another variant:
execvP
(with uppercaseP
). This is likeexecvp()
, but instead of getting the search path from thePATH
environment variable, it’s an explicit parameter to the function:
int execvP(const char *file, const char *search_path, char *const argv[]);