Skip to content

Latest commit

 

History

History
78 lines (68 loc) · 7.84 KB

process-and-environment-control.md

File metadata and controls

78 lines (68 loc) · 7.84 KB
descriptiontitlems.datef1_keywordshelpviewer_keywords
Learn more about: Process and Environment Control
Process and Environment Control
11/04/2016
c.programs
processes, stopping
processes, administrative tasks
parent process
processes, starting
environment control routines
process control routines

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

RoutineUse
abortAbort process without flushing buffers or calling functions registered by atexit and _onexit
assertTest for logic error
_ASSERT, _ASSERTE macrosSimilar to assert, but only available in the debug versions of the run-time libraries
atexitSchedule routines for execution at program termination
_beginthread, _beginthreadexCreate a new thread on a Windows operating system process
_cexitPerform exit termination procedures (such as flushing buffers), then return control to calling program without terminating process
_c_exitPerform _exit termination procedures, then return control to calling program without terminating process
_cwaitWait until another process terminates
_endthread, _endthreadexTerminate a Windows operating system thread
_execl, _wexeclExecute new process with argument list
_execle, _wexecleExecute new process with argument list and given environment
_execlp, _wexeclpExecute new process using PATH variable and argument list
_execlpe, _wexeclpeExecute new process using PATH variable, given environment, and argument list
_execv, _wexecvExecute new process with argument array
_execve, _wexecveExecute new process with argument array and given environment
_execvp, _wexecvpExecute new process using PATH variable and argument array
_execvpe, _wexecvpeExecute new process using PATH variable, given environment, and argument array
exitCall functions registered by atexit and _onexit, flush all buffers, close all open files, and terminate process
_exitTerminate process immediately without calling atexit or _onexit or flushing buffers
getenv, _wgetenv, getenv_s, _wgetenv_sGet value of environment variable
_getpidGet process ID number
longjmpRestore saved stack environment; use it to execute a nonlocal goto
_onexitSchedule routines for execution at program termination; use for compatibility with Microsoft C/C++ version 7.0 and earlier
_pcloseWait for new command processor and close stream on associated pipe
perror, _wperrorPrint error message
_pipeCreate pipe for reading and writing
_popen, _wpopenCreate pipe and execute command
_putenv, _wputenv, _putenv_s, _wputenv_sAdd or change value of environment variable
raiseSend signal to calling process
setjmpSave stack environment; use to execute non local goto
signalHandle interrupt signal
_spawnl, _wspawnlCreate and execute new process with specified argument list
_spawnle, _wspawnleCreate and execute new process with specified argument list and environment
_spawnlp, _wspawnlpCreate and execute new process using PATH variable and specified argument list
_spawnlpe, _wspawnlpeCreate and execute new process using PATH variable, specified environment, and argument list
_spawnv, _wspawnvCreate and execute new process with specified argument array
_spawnve, _wspawnveCreate and execute new process with specified environment and argument array
_spawnvp, _wspawnvpCreate and execute new process using PATH variable and specified argument array
_spawnvpe, _wspawnvpeCreate and execute new process using PATH variable, specified environment, and argument array
system, _wsystemExecute operating-system command

In the Windows operating system, the spawned process is equivalent to the spawning process. 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 can't 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 and _spawn families 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

FunctionsUse PATH variable to locate fileArgument-passing conventionEnvironment settings
_execl, _spawnlNoListInherited from calling process
_execle, _spawnleNoListPointer to environment table for new process passed as last argument
_execlp, _spawnlpYesListInherited from calling process
_execvpe, _spawnvpeYesArrayPointer to environment table for new process passed as last argument
_execlpe, _spawnlpeYesListPointer to environment table for new process passed as last argument
_execv, _spawnvNoArrayInherited from calling process
_execve, _spawnveNoArrayPointer to environment table for new process passed as last argument
_execvp, _spawnvpYesArrayInherited from calling process

See also

Universal C runtime routines by category

close