Home

execvp

execvp is a function in the POSIX C library used to replace the current process image with a new program. It is part of the exec family of functions. The prototype is int execvp(const char *file, char *const argv[]); The argv array must be terminated by a NULL pointer, and argv[0] is conventionally the name of the program being executed.

execvp searches for the specified file in the directories listed in the PATH environment variable, unless the

The environment of the new program is inherited from the calling process. It does not take an

Typical usage involves forking a process and calling execvp in the child to run a different program

---

file
name
contains
a
slash,
in
which
case
PATH
is
not
searched
and
the
file
is
attempted
directly.
If
a
suitable
executable
is
found
and
loaded,
the
current
process
image
is
replaced
by
the
new
program
and
control
does
not
return
to
the
caller.
If
execution
fails,
the
function
returns
-1
and
errno
is
set
to
indicate
the
error
(examples
include
ENOENT
for
a
missing
file,
EACCES
for
permission
denied,
ENOEXEC
for
an
invalid
executable
format).
explicit
environment
parameter.
To
supply
a
custom
environment,
one
would
use
a
variant
such
as
execve
(which
accepts
an
envp
argument)
or
platform-specific
variants
like
execvpe
that
combine
PATH
search
with
a
custom
environment.
while
allowing
the
parent
to
continue
or
terminate
independently.