Home

execlp

execlp is a member of the exec family of functions defined by the POSIX standard, used to replace the current process image with a new program. The “p” suffix indicates that the function searches for the executable file in the directories listed in the PATH environment variable, while the leading “l” denotes that the arguments are passed as a variable‑length list rather than as an array.

The prototype, declared in \<unistd.h\>, is

int execlp(const char *file, const char *arg0, ..., (char *)NULL);

The first argument, *file*, names the program to execute. If *file* does not contain a slash, execlp

On success, execlp does not return; the original process image is entirely replaced. On failure, it returns

Related functions include execl, execle, execv, execvp, and execvpe, differing in how they accept arguments and

searches
each
directory
in
PATH
for
an
executable
file
with
that
name.
The
subsequent
arguments
constitute
the
argument
vector
passed
to
the
new
program,
ending
with
a
null
pointer.
The
first
argument
(arg0)
conventionally
contains
the
filename
itself,
as
the
new
program
expects.
–1
and
sets
errno
to
indicate
the
error,
such
as
ENOENT
(file
not
found),
EACCES
(permission
denied),
or
ENOMEM
(insufficient
memory).
Because
the
function
overlays
the
current
process,
any
open
file
descriptors,
signal
dispositions,
and
environment
variables
persist
unless
explicitly
altered
before
the
call.
whether
they
perform
PATH
search.
execlp
is
commonly
used
after
a
fork
to
run
a
different
program
in
the
child
process,
enabling
the
parent
to
continue
execution.
Care
should
be
taken
to
avoid
passing
untrusted
input
as
arguments,
as
this
can
lead
to
command
injection
or
unintended
behavior.