Exec (operating system)

Exec (operating system)

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

In the "execl", "execlp", "execv", and "execvp" calls, the child process inherits the parent's environment.

Files open when an "exec" call is made remain open in the new process. All open files must be flushed before an "exec" call.The "exec" calls do not preserve the translation modes of open files. If the child process uses files inherited from the parent, "setmode" function can be called to set the translation mode to the desired mode.

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. [http://www.gnu.org/software/bash/manual/bashref.html#IDX74 - "exec" built-in command in bash manual] "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. [http://tldp.org/LDP/abs/html/wrapper.html]

Prototypes

The functions are declared in unistd.h for POSIX standard and in process.h for DOS, OS/2, Windows.

:int execl(const char *path, const char *arg0, ...);:int execle(const char *path, const char *arg0, ..., const char *const *envp);:int execlp(const char *path, const char *arg0, ...);:int execlpe(const char *path, const char *arg0, ...);:int execv(const char *path, const char *const *argv);:int execve(const char *path, const char *const *argv, const char *const *envp);:int execvp(const char *path, const char *const *argv);:int execvpe(const char *path, const char *const *argv, const char *const *envp);

*"Note: Some implementations provide these functions named with a leading underscore (e.g. _execl)".

Function names

The base of each function is exec, followed by one or more letters::e - An array of pointers to environment arguments is explicitly passed to the child process. :l - Command-line arguments are passed individually to the function. :p - Uses the path argument variable to find the file to be executed. :v - Command-line arguments are passed to the function as an array of pointers.

Path

The path argument specifies the path name of the file to execute as a child process. Arguments arg0 through argn are a list of pointers to arguments to be passed to the child process. argv is an array of pointers to arguments.

Envp

Argument envp is an array of pointers to environment settings. The execle, execlpe, execve, and execvpe calls alter the environment for the child process by passing a list of environment settings through the envp argument. This argument is an array of character pointers; each element (except for the final element) points to a null-terminated string defining an environment variable.

Each null-terminated string has the form::name=value

where name is the environment variable name, and value is the value of that that variable. The final element of the envp array must be null. If envp itself is null, the child process inherits the environment settings of the parent process.

Return Value

The "exec" functions do not normally return to the calling process. If an exec function returns, an error occurred, the return value is -1, and errno is set to one of the following values:

ee also

*Exit
*Fork
*Fork-exec
*Overlay
*Path (variable)
*Spawn

References

External links

*man|sh|exec|SUS|execute a file


Wikimedia Foundation. 2010.

Игры ⚽ Поможем решить контрольную работу

Look at other dictionaries:

  • Operating system — Operating systems …   Wikipedia

  • Fork (operating system) — In computing, when a process forks, it creates a copy of itself, which is called a child process. The original process is then called the parent process . More generally, a fork in a multithreading environment means that a thread of execution is… …   Wikipedia

  • Cray Operating System — Company / developer Cray Research Working state Historic Latest stable release 1.17.2 / July, 1990 License Proprietary The Cray Operating System (COS) was Cray Research s proprietary operating system f …   Wikipedia

  • Exit (operating system) — A computer process terminates its execution by making an exit system call. More generally, an exit in a multithreading environment means that a thread of execution has stopped running. The operating system reclaims resources (memory, files, etc.) …   Wikipedia

  • EOS (operating system) — Infobox OS name = EOS logo = caption = developer = ETA Systems source model = VSOS kernel type = hybrid distributed supported platforms = ETA10 line of supercomputers ui = Command line interface family = Lineage likely from CDC back to Univac… …   Wikipedia

  • LOCUS (operating system) — Infobox OS name = LOCUS developer = UCLA family = Unix source model = Closed source working state = Historic kernel type = Monolithic kernel license = Proprietary LOCUS was a distributed operating system developed at UCLA during the 1980s. It was …   Wikipedia

  • Overlay (operating system) — For the division of a single program to reduce memory requirements, see Overlay (programming). In operating systems, an overlay is when a process replaces itself with the code of another program. On Unix like systems, this is accomplished with… …   Wikipedia

  • Cray Operating System — Basisdaten Entwickler Cray Research Version 1.17.2 (Juli 1990) Lizenz …   Deutsch Wikipedia

  • Fedora (operating system) — infobox OS name = Fedora caption = Fedora 9 running GNOME developer = Fedora Project family = Linux, Unix like source model = Various working state = Current released = 2003 11 16 latest release version = 9 latest release date = release… …   Wikipedia

  • Cray Operating System — Разработчик Cray Research Последняя версия 1.13 1990 год Лицензия Общественное достояние Состояние Историческое Cray Operating System (COS)  проприетарная операционная система, разработанная компанией …   Википедия

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”