In computing, exec is a functionality of an operating system that runs an in the context of an already existing process, replacing the previous executable. This act is also referred to as an overlay. It is especially important in Unix-like systems, although it exists elsewhere. As no new process is created, the process identifier (PID) does not change, but the machine code, data, heap, and stack of the process are replaced by those of the new program.
The exec call is available for many programming languages including compilable languages and some scripting languages. In OS command interpreters, the built-in command replaces the shell process with the specified program.
Interfaces to exec and its implementations vary. Depending on programming language it may be accessible via one or more functions, and depending on operating system it may be represented with one or more actual system calls. For this reason exec is sometimes described as a collection of functions.
Standard names of such functions in C are , , , , , and (see below), but not "exec" itself. The Linux kernel has one corresponding system call named "execve", whereas all aforementioned functions are user-space wrappers around it.
Higher-level languages usually provide one call named .
The POSIX standard declares exec functions in the header file, in the C language. The same functions are declared in for DOS (see below), OS/2, and Microsoft Windows.
int execl(char const *path, char const *arg0, ...);
int execle(char const *path, char const *arg0, ..., char const *envp[]);
int execlp(char const *file, char const *arg0, ...);
int execv(char const *path, char const *argv[]);
int execve(char const *path, char const *argv[], char const *envp[]);
int execvp(char const *file, char const *argv[]);
int fexecve(int fd, char *const argv[], char *const envp[]);
Some implementations provide these functions named with a leading underscore (e.g. _execl).
The base of each is exec (execute), followed by one or more letters:
e – An array of pointers to environment variables is explicitly passed to the new process image.