Exec (operating System)

Exec (operating System)

The exec collection of functions of Unix-like operating systems cause the running process to be completely replaced by the program passed as an argument to the function. As a new process is not created, the process identifier (PID) does not change, but the data, heap and stack of the original process are replaced by those of the new process.

In the execl, execlp, execv, and execvp calls, the new process image inherits the current environment variables.

Files open when an exec call is made remain open in the new process. This aspect is used to specify the standard streams (stdin, stdout and stderr) of the new process.

In MS-DOS environments, a program executed with one of the exec functions is always loaded into memory as if the "maximum allocation" in the program's executable file header is set to default value 0xFFFF. The EXEHDR utility can be used to change the maximum allocation field of a program. However, if this is done and the program is invoked with one of the exec functions, the program might behave differently from a program invoked directly from the operating-system command line or with one of the spawn functions.

Many Unix shells also offer an exec built-in command that replaces the shell process with the specified program. Wrapper scripts often use this command to run a program (either directly or through an interpreter or virtual machine) after setting environment variables or other configuration. By using exec, the resources used by the shell program do not need to stay in use after the program is started.

Read more about Exec (operating System):  Prototypes, Return Value

Other articles related to "exec":

Exec (operating System) - Return Value
... Normally the execfunction will replace the current process,so it cannot return anything to the original process ... Processes do have an exit status,but that value is collected by the parent process ... If an execfunction does return to the calling process,an error occurred,the return value is 1,and errno is set to one of the following values Name Notes E2BIG The argument list exceeds the system limit ...