OpenBSD manual page server

Manual Page Search Parameters

EXECV(3) Library Functions Manual EXECV(3)

execv, execl, execle — execute a file

#include <unistd.h>

extern char **environ;

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

int
execl(const char *path, const char *arg, ...);

int
execle(const char *path, const char *arg, ..., char *const envp[]);

These functions replace the current process image with a new process image constructed from the file at the specified path. They are front-ends for the execve(2) system call; see that manual page for detailed information about the replacement of the current process.

The () function receives the argument list for the new process in the form of a NULL-terminated array of pointers to NUL-terminated strings. The first argument, by convention, should point to the file name associated with the file being executed. Calling execv() is equivalent to calling execve(2) and passing the environ array as the last parameter.

The () and execle() functions receive each element of the same NULL-terminated argument array as a separate function parameter, that is, arg and the subsequent ellipsis can be thought of as argv[0], argv[1], ..., argv[argc]. For execl(), the environment for the new process image is again taken from the external variable environ in the current process.

The () function specifies the environment of the new process by following the NULL pointer that terminates the list of arguments in the parameter list with a NULL-terminated array of pointers to NUL-terminated strings, each one conventionally being of the form name=value.

If any of these functions return, an error has occurred. The return value is -1, and the global variable errno is set to indicate the error.

execv() may fail and set errno for any of the errors specified for the library function execve(2).

execl() and execle() may also fail and set errno for any of the errors specified for the library function mmap(2).

execve(2), fork(2), ktrace(2), ptrace(2), execvp(3), environ(7)

execv(), execl(), and execle() conform to IEEE Std 1003.1-1988 (“POSIX.1”).

The functions execv() and execl() first appeared in Version 2 AT&T UNIX. The functions execve() and execle() first appeared in Version 7 AT&T UNIX.

OpenBSD-current September 19, 2026 EXECV(3)