Spawn (computing)
Encyclopedia
Spawn in computing
Computing
Computing is usually defined as the activity of using and improving computer hardware and software. It is the computer-specific part of information technology...

 refers to a function that loads and executes
Execution (computers)
Execution in computer and software engineering is the process by which a computer or a virtual machine carries out the instructions of a computer program. The instructions in the program trigger sequences of simple actions on the executing machine...

 a new child process
Child process
A child process in computing is a process created by another process .A child process inherits most of its attributes, such as open files, from its parent. In UNIX, a child process is in fact created as a copy of the parent...

.
The current process
Parent process
In computing, a parent process is a process that has created one or more child processes.- Unix :In the operating system Unix, every process except is created when another process executes the fork system call. The process that invoked fork is the parent process and the newly-created process is...

 may or may not continue to execute asynchronously. 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 the Microsoft Windows
Microsoft Windows
Microsoft Windows is a series of operating systems produced by Microsoft.Microsoft introduced an operating environment named Windows on November 20, 1985 as an add-on to MS-DOS in response to the growing interest in graphical user interfaces . Microsoft Windows came to dominate the world's personal...

 line of operating system
Operating system
An operating system is a set of programs that manage computer hardware resources and provide common services for application software. The operating system is the most important type of system software in a computer system...

s.
There is also a different family of spawn functions in an optional extension of the POSIX
POSIX
POSIX , an acronym for "Portable Operating System Interface", is a family of standards specified by the IEEE for maintaining compatibility between operating systems...

 standards
.

Different versions

The Microsoft Windows
Microsoft Windows
Microsoft Windows is a series of operating systems produced by Microsoft.Microsoft introduced an operating environment named Windows on November 20, 1985 as an add-on to MS-DOS in response to the growing interest in graphical user interfaces . Microsoft Windows came to dominate the world's personal...

 spawn functions are inspired by Unix
Unix
Unix is a multitasking, multi-user computer operating system originally developed in 1969 by a group of AT&T employees at Bell Labs, including Ken Thompson, Dennis Ritchie, Brian Kernighan, Douglas McIlroy, and Joe Ossanna...

 functions fork
Fork (operating system)
In computing, when a process forks, it creates a copy of itself. More generally, a fork in a multithreading environment means that a thread of execution is duplicated, creating a child thread from the parent thread....

 and exec
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...

; however, as Windows does not support fork (at least in the Win32 API; POSIX
POSIX
POSIX , an acronym for "Portable Operating System Interface", is a family of standards specified by the IEEE for maintaining compatibility between operating systems...

 emulation environments such as Cygwin
Cygwin
Cygwin is a Unix-like environment and command-line interface for Microsoft Windows. Cygwin provides native integration of Windows-based applications, data, and other system resources with applications, software tools, and data of the Unix-like environment...

 or SFU
Microsoft Windows Services for UNIX
Windows Services for UNIX or Subsystem for UNIX-based Applications is a software package produced by Microsoft which provides a Unix subsystem and other parts of a full Unix environment on Windows NT and some of its immediate successor operating-systems...

 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.

The Posix spawn functions were introduced to enable support for processes in Posix implementations for embedded environments that don't support swapping or dynamic address translation .

Microsoft Windows spawn functions

In the spawnl, spawnlp, spawnv, and spawnvp 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:
Name Notes
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.

Mode

The mode argument determines the way the child is run. Values for mode are:
Name Notes
P_OVERLAY Overlays parent process with child, which destroys the parent. This has the same effect as the exec* functions.
P_WAIT Suspends parent process until the child process has finished executing (synchronous spawn).
P_NOWAIT, P_NOWAITO Continues to execute calling process concurrently with new process (asynchronous spawn).
P_DETACH the child is run in background without access to the console or keyboard. Calls to _cwait upon the new process will fail (asynchronous spawn)

Path

The path argument specifies the filename of the program to execute. For spawnlp and spawnvp only, if the filename does not have a path and is not in the current directory, the PATH environment variable
Path (variable)
PATH is an environment variable on Unix-like operating systems, DOS, OS/2, and Microsoft Windows, specifying a set of directories where executable programs are located...

 determines which directories to search for the file. The string pointed to by argv[0] 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 argn, in the spawn call. The accepted maximum combined length of these strings differs between compilers, ranging from 128 characters on Digital Mars to 1024 on Microsoft Visual C++ or
as much as memory permits, on DJGPP.. The last argument after argn 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, spawnlpe, spawnve, and spawnvpe calls allow the user to alter the child process's environment by passing a list of environment settings in the envp 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 envp argument is null, the child inherits the parent's environment settings.

The spawn functions can be used under Microsoft Windows. They use LoadModule to run the spawned process. 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
Abnormal end
An ABEND is an abnormal termination of software, or a program crash.This usage derives from an error message from the IBM OS/360, IBM zOS operating systems. Usually capitalized, but may appear as "abend"...

 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:
Value Notes
-2 File not found
-3 Path not found
-11 Invalid .exe file (for Windows)
-13 DOS 4. 0 application
-14 Unknown .exe type (may be DOS extended)

See also

  • Fork
    Fork (operating system)
    In computing, when a process forks, it creates a copy of itself. More generally, a fork in a multithreading environment means that a thread of execution is duplicated, creating a child thread from the parent thread....

  • Exec
    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...

  • fork-exec
    Fork-exec
    Fork-exec is a commonly used technique in Unix whereby an executing process spawns a new program. fork is the name of the system call that the parent process uses to "divide" itself . After calling fork, the created child process is an exact copy of the parent except for the return value...

  • Path (variable)
    Path (variable)
    PATH is an environment variable on Unix-like operating systems, DOS, OS/2, and Microsoft Windows, specifying a set of directories where executable programs are located...

  • Process.h
    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 library functions in their C library...

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK