HOME

TheInfoList



OR:

Spawn in
computing Computing is any goal-oriented activity requiring, benefiting from, or creating computing machinery. It includes the study and experimentation of algorithmic processes, and development of both hardware and software. Computing has scientific, ...
refers to a function that loads and executes a new
child process A child process in computing is a process created by another process (the parent process). This technique pertains to multitasking operating systems, and is sometimes called a subprocess or traditionally a subtask. There are two major procedure ...
. The current process may wait for the child to terminate or may continue to execute
concurrent computing Concurrent computing is a form of computing in which several computations are executed '' concurrently''—during overlapping time periods—instead of ''sequentially—''with one completing before the next starts. This is a property of a sys ...
. Creating a new subprocess requires enough memory in which both the child process and the current program can execute. There is a family of spawn functions in DOS, inherited by Microsoft Windows. There is also a different family of spawn functions in an optional extension of the
POSIX The Portable Operating System Interface (POSIX) is a family of standards specified by the IEEE Computer Society for maintaining compatibility between operating systems. POSIX defines both the system- and user-level application programming inte ...
standards .Posix.1-2008 spawn.h
/ref>


DOS/Windows spawn functions

The DOS/Windows spawn functions are inspired by
Unix Unix (; trademarked as UNIX) is a family of multitasking, multiuser computer operating systems that derive from the original AT&T Unix, whose development started in 1969 at the Bell Labs research center by Ken Thompson, Dennis Ritchie, a ...
functions fork and exec; however, as these operating systems do not support fork,for
Windows NT Windows NT is a proprietary graphical operating system produced by Microsoft, the first version of which was released on July 27, 1993. It is a processor-independent, multiprocessing and multi-user operating system. The first version of Wi ...
at least in the Win32 API;
POSIX The Portable Operating System Interface (POSIX) is a family of standards specified by the IEEE Computer Society for maintaining compatibility between operating systems. POSIX defines both the system- and user-level application programming inte ...
emulation environments such as Cygwin, or
SFU Simon Fraser University (SFU) is a public research university in British Columbia, Canada, with three campuses, all in Greater Vancouver: Burnaby (main campus), Surrey, and Vancouver. The main Burnaby campus on Burnaby Mountain, located from ...
do
the spawn function was supplied as a replacement for the fork-exec combination. However, the spawn function, although it deals adequately with the most common use cases, lacks the full power of fork-exec, since after fork any process settings which will survive an exec may be changed. However, in most cases, this deficiency can be made up for by using the more low-level CreateProcess API. In the ''spawnl'', ', ''spawnv'', and ' calls, the child process inherits the environment of the parent. Files that are open when a ''spawn'' call is made remain open in the child process.


Prototype

:int spawnl(int mode, char *path, char *arg0, ...); :int spawnle(int mode, char *path, char *arg0, ..., char ** envp); :int spawnlp(int mode, char *path, char *arg0, ...); :int spawnlpe(int mode, char *path, char *arg0, ..., char ** envp); :int spawnv(int mode, char *path, char **argv); :int spawnve(int mode, char *path, char **argv, char ** envp); :int spawnvp(int mode, char *path, char **argv); :int spawnvpe(int mode, char *path, char **argv, char ** envp);


Function names

The base name of each function is spawn, followed by one or more letters:


Mode

The ''mode'' argument determines the way the child is run. Values for ''mode'' are:


Path

The ''path'' argument specifies the filename of the program to execute. For ' and ' only, if the filename does not have a path and is not in the current directory, the PATH environment variable determines which directories to search for the file. The string pointed to by ''argv'' is the name of the program to run. The command line passed to the spawned program is made up of the character strings, ''arg0'' through ', in the ''spawn'' call. The accepted maximum combined length of these strings differs between compilers, ranging from 128 characters on Digital MarsDigital Mars process.h
/ref> to 1024 on Microsoft Visual C++Microsoft MSDN
/ref> or as much as memory permits, on DJGPP.
/ref> The last argument after has to be a NULL pointer.


argv

The ''argv'' argument is an array of character pointers. The last pointer in the array must be null to indicate the end of the list.


envp

The ''spawnle'', ', ', and ' calls allow the user to alter the child process's environment by passing a list of environment settings in the ' argument. This argument is an array of character pointers; each pointer (except for the last one) points to a null-terminated string defining an environment variable. An environment variable has the form: ''name''=''value'' where ''name'' is the variable name and ''value'' is its value. The last pointer in the array is null. When the ' argument is null, the child inherits the parent's environment settings. Under Microsoft Windows, the ''spawn*'' functions use LoadModule to run the spawned process; and if this fails, an attempt is made to spawn a normal MS-DOS process. If a Windows application is spawned, the instance handle can be obtained using ''exec_instancehandleget''. It is possible to specify how the spawned program will be shown using the functions ''_exec_showset'', ''_exec_showget'', and ''_exec_showreset''.


Return values

The return value indicates the exit status of the spawned program. A value of zero indicates that the spawned program executed successfully. A positive value indicates that the spawned program executed, but was
aborted Aborted is a Belgian death metal band formed in 1995 in Waregem. The group currently consists of vocalist, founder and only constant member Sven de Caluwé, guitarist Ian Jekelis, bassist Stefano Franceschini and drummer Ken Bedene. Although t ...
or ended in error, the value returned is the exit status of the child process. A negative value indicates that the spawned program did not execute, and errno is set. Under Microsoft Windows, ''spawn'' returns the negated error code returned from LoadModule for compatibility with the C run-time library. The following error codes may be encountered:


POSIX spawn functions

The and its sibling posix_spawnp can be used as replacements for fork and exec, but does not provide the same flexibility as using fork and exec separately. They may be efficient replacements for fork and exec, but their purpose is to provide process creation primitives in embedded environments where fork is not supported due to lack of
dynamic address translation The IBM System/360 Model 67 (S/360-67) was an important IBM mainframe model in the late 1960s. * It had "its own powerful operating system... heTime Sharing System monitor (TSS)" offering "virtually instantaneous access to and response from t ...
.


History

The ''spawn'' metaphor, i.e., to produce offspring as in egg deposition, had its early use in the VMS, now
OpenVMS OpenVMS, often referred to as just VMS, is a multi-user, multiprocessing and virtual memory-based operating system. It is designed to support time-sharing, batch processing, transaction processing and workstation applications. Customers using Ope ...
, operating system (1977). In academia, there existed a lively debate between proponents of the
Unix Unix (; trademarked as UNIX) is a family of multitasking, multiuser computer operating systems that derive from the original AT&T Unix, whose development started in 1969 at the Bell Labs research center by Ken Thompson, Dennis Ritchie, a ...
''fork'' (crude copy of memory layout, but fast) versus VMS's ''spawn'' (reliable construction of process parameters, but slower). This debate revived when the VMS spawning mechanism was inherited by
Windows NT Windows NT is a proprietary graphical operating system produced by Microsoft, the first version of which was released on July 27, 1993. It is a processor-independent, multiprocessing and multi-user operating system. The first version of Wi ...
(1993).


See also

* Fork * Exec * fork-exec * Path (variable) *
Process.h process.h is a C header file which contains function declarations and macros used in working with threads and processes. Most C compilers that target DOS, Windows 3.1x, Win32, OS/2, Novell NetWare or DOS extenders supply this header and the librar ...


References

{{Reflist Process (computing) C POSIX library Process.h