Each application running under OS/2 typically resides in its own process, and therefore has its own address space. Resources created by or allocated to a process are normally private to that process. If required for application purposes, this process may in turn create one or more additional processes to perform part of the application's processing. Additional processes may be created in either of two ways:
When an application uses multiple processes, it is usual for the first process to be regarded as the "primary" process for the application, and for other processes to be started as children of this process. This is conceptually similar to the use of primary and secondary threads.
It is therefore conventional to use the DosExecPgm() function to start a child process. This function is illustrated in Figure "Starting a Child Process".
The window handle of the window from which the DosExecPgm() call is made, is passed to the child process as an argument, using the the fourth parameter of the DosExecPgm() function. This enables the child process to post a message to its parent upon completing its initialization, indicating the window handle of its own window. In this way, communication via Presentation Manager messages may be established in both directions.
Note that since the fourth parameter to the DosExecPgm() function is defined as an ASCII string, the window handle is converted to its ASCII equivalent before the call is issued. The main routine of the child process subsequently converts the handle back to its true form.
Use of the EXEC_ASYNCRESULT flag in the DosExecPgm() call causes the operating system to save the termination codes of the child process so that they may be examined at a later point by the parent process, using a DosWaitChild() function call for synchronization purposes (see Figure "DosWaitChild() Function" for further information).
The process ID of the child process is returned by the DosExecPgm() function as part of the RESULTCODES structure in the sixth parameter. This value should be stored by the parent process, since it is used if and when the parent process needs to terminate the child at some later point during execution.