Process and Environment Control

Use the process-control routines to start, stop, and manage processes from within a program. Use the environment-control routines to get and change information about the operating-system environment.

Process and Environment Control Functions

Routine Use
abort Abort process without flushing buffers or calling functions registered by atexit and _onexit
assert Test for logic error
_ASSERT, _ASSERTE macros Similar to assert, but only available in the debug versions of the run-time libraries
atexit Schedule routines for execution at program termination
_beginthread, _beginthreadex Create a new thread on a Windows NT or Windows 95 process
_cexit Perform exit termination procedures (such as flushing buffers), then return control to calling program without terminating process
_c_exit Perform _exit termination procedures, then return control to calling program without terminating process
_cwait Wait until another process terminates
_endthread, _endthreadex Terminate a Windows NT or Windows 95 thread
_execl, _wexecl Execute new process with argument list
_execle, _wexecle Execute new process with argument list and given environment
_execlp, _wexeclp Execute new process using PATH variable and argument list
_execlpe, _wexeclpe Execute new process using PATH variable, given environment, and argument list
_execv, _wexecv Execute new process with argument array
_execve, _wexecve Execute new process with argument array and given environment
_execvp, _wexecvp Execute new process using PATH variable and argument array
_execvpe, _wexecvpe Execute new process using PATH variable, given environment, and argument array
exit Call functions registered by atexit and _onexit, flush all buffers, close all open files, and terminate process
_exit Terminate process immediately without calling atexit or _onexit or flushing buffers
getenv, _wgetenv Get value of environment variable
_getpid Get process ID number
longjmp Restore saved stack environment; use it to execute a nonlocal goto
_onexit Schedule routines for execution at program termination; use for compatibility with Microsoft C/C++ version 7.0 and earlier
_pclose Wait for new command processor and close stream on associated pipe
perror, _wperror Print error message
_pipe Create pipe for reading and writing
_popen, _wpopen Create pipe and execute command
_putenv, _wputenv Add or change value of environment variable
raise Send signal to calling process
setjmp Save stack environment; use to execute nonlocal goto
signal Handle interrupt signal
_spawnl, _wspawnl Create and execute new process with specified argument list
_spawnle, _wspawnle Create and execute new process with specified argument list and environment
_spawnlp, _wspawnlp Create and execute new process using PATH variable and specified argument list
_spawnlpe, _wspawnlpe Create and execute new process using PATH variable, specified environment, and argument list
_spawnv, _wspawnv Create and execute new process with specified argument array
_spawnve, _wspawnve Create and execute new process with specified environment and argument array
_spawnvp, _wspawnvp Create and execute new process using PATH variable and specified argument array
_spawnvpe, _wspawnvpe Create and execute new process using PATH variable, specified environment, and argument array
system, _wsystem Execute operating-system command

In Windows NT and Windows 95, the spawned process is equivalent to the spawning process. Therefore, the OS/2® wait function, which allows a parent process to wait for its children to terminate, is not available. Instead, any process can use _cwait to wait for any other process for which the process ID is known.

The difference between the _exec and _spawn families is that a _spawn function can return control from the new process to the calling process. In a _spawn function, both the calling process and the new process are present in memory unless _P_OVERLAY is specified. In an _exec function, the new process overlays the calling process, so control cannot return to the calling process unless an error occurs in the attempt to start execution of the new process.

The differences among the functions in the _exec family, as well as among those in the _spawn family, involve the method of locating the file to be executed as the new process, the form in which arguments are passed to the new process, and the method of setting the environment, as shown in the following table. Use a function that passes an argument list when the number of arguments is constant or is known at compile time. Use a function that passes a pointer to an array containing the arguments when the number of arguments is to be determined at run time. The information in the following table also applies to the wide-character counterparts of the _spawn and _exec functions.

_spawn and _exec Function Families



Functions
Use PATH
Variable to
Locate File
Argument-
Passing
Convention

Environment Settings
_execl, _spawnl No List Inherited from calling process
_execle, _spawnle No List Pointer to environment table for new process passed as last argument
_execlp, _spawnlp Yes List Inherited from calling process
_execlpe, _spawnlpe Yes List Pointer to environment table for new process passed as last argument
_execv, _spawnv No Array Inherited from calling process
_execve, _spawnve No Array Pointer to environment table for new process passed as last argument
_execvp, _spawnvp Yes Array Inherited from calling process
_execvpe, _spawnvpe Yes Array Pointer to environment table for new process passed as last argument