Process and Environment Control

 

For the latest documentation on Visual Studio 2017 RC, see Visual Studio 2017 RC Documentation.

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.NET Framework equivalent
abortAbort process without flushing buffers or calling functions registered by atexit and _onexitNot applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.
assertTest for logic errorSystem::Diagnostics::Debug::Assert
_ASSERT, _ASSERTE macrosSimilar to assert, but only available in the debug versions of the run-time librariesSystem::Diagnostics::Debug::Assert
atexitSchedule routines for execution at program terminationSystem::Diagnostics::Process::Exited
_beginthread, _beginthreadexCreate a new thread on a Windows operating system processSystem::Threading::Thread::Start
_cexitPerform exit termination procedures (such as flushing buffers), then return control to calling program without terminating processSystem::Diagnostics::Process::CloseMainWindow
_c_exitPerform _exit termination procedures, then return control to calling program without terminating processSystem::Diagnostics::Process::CloseMainWindow
_cwaitWait until another process terminatesSystem::Diagnostics::Process::WaitForExit
_endthread, _endthreadexTerminate a Windows operating system threadNot applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.
_execl, _wexeclExecute new process with argument listSystem::Diagnostics::Process Class, System::Diagnostics::ProcessStartInfo Class
_execle, _wexecleExecute new process with argument list and given environmentSystem::Diagnostics::Process Class, System::Diagnostics::ProcessStartInfo Class
_execlp, _wexeclpExecute new process using PATH variable and argument listSystem::Diagnostics::Process Class, System::Diagnostics::ProcessStartInfo Class
_execlpe, _wexeclpeExecute new process using PATH variable, given environment, and argument listSystem::Diagnostics::Process Class, System::Diagnostics::ProcessStartInfo Class
_execv, _wexecvExecute new process with argument arraySystem::Diagnostics::Process Class, System::Diagnostics::ProcessStartInfo Class
_execve, _wexecveExecute new process with argument array and given environmentSystem::Diagnostics::Process Class, System::Diagnostics::ProcessStartInfo Class
_execvp, _wexecvpExecute new process using PATH variable and argument arraySystem::Diagnostics::Process Class, System::Diagnostics::ProcessStartInfo Class
_execvpe, _wexecvpeExecute new process using PATH variable, given environment, and argument arraySystem::Diagnostics::Process Class, System::Diagnostics::ProcessStartInfo Class
exitCall functions registered by atexit and _onexit, flush all buffers, close all open files, and terminate processSystem::Diagnostics::Process::Kill
_exitTerminate process immediately without calling atexit or _onexit or flushing buffersSystem::Diagnostics::Process::Kill
getenv, _wgetenv, getenv_s, _wgetenv_sGet value of environment variableSystem::Environment::GetEnvironmentVariable
_getpidGet process ID numberSystem::Diagnostics::Process::Id
longjmpRestore saved stack environment; use it to execute a nonlocal gotoNot applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.
_onexitSchedule routines for execution at program termination; use for compatibility with Microsoft C/C++ version 7.0 and earlierSystem::Diagnostics::Process::Exited
_pcloseWait for new command processor and close stream on associated pipeNot applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.
perror, _wperrorPrint error messageNot applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.
_pipeCreate pipe for reading and writingNot applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.
_popen, _wpopenCreate pipe and execute commandNot applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.
_putenv, _wputenv, _putenv_s, _wputenv_sAdd or change value of environment variableNot applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.
raiseSend signal to calling processNot applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.
setjmpSave stack environment; use to execute non local gotoNot applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.
signalHandle interrupt signalNot applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.
_spawnl, _wspawnlCreate and execute new process with specified argument listSystem::Diagnostics::Process Class, System::Diagnostics::ProcessStartInfo Class
_spawnle, _wspawnleCreate and execute new process with specified argument list and environmentSystem::Diagnostics::Process Class, System::Diagnostics::ProcessStartInfo Class
_spawnlp, _wspawnlpCreate and execute new process using PATH variable and specified argument listSystem::Diagnostics::Process Class, System::Diagnostics::ProcessStartInfo Class
_spawnlpe, _wspawnlpeCreate and execute new process using PATH variable, specified environment, and argument listSystem::Diagnostics::Process Class, System::Diagnostics::ProcessStartInfo Class
_spawnv, _wspawnvCreate and execute new process with specified argument arraySystem::Diagnostics::Process Class, System::Diagnostics::ProcessStartInfo Class
_spawnve, _wspawnveCreate and execute new process with specified environment and argument arraySystem::Diagnostics::Process Class, System::Diagnostics::ProcessStartInfo Class
_spawnvp, _wspawnvpCreate and execute new process using PATH variable and specified argument arraySystem::Diagnostics::Process Class, System::Diagnostics::ProcessStartInfo Class
_spawnvpe, _wspawnvpeCreate and execute new process using PATH variable, specified environment, and argument arraySystem::Diagnostics::Process Class, System::Diagnostics::ProcessStartInfo Class
system, _wsystemExecute operating-system commandSystem::Diagnostics::ProcessStartInfo Class, System::Diagnostics::Process Class

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 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

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
_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
_execvpe, _spawnvpeYesArrayPointer to environment table for new process passed as last argument

Run-Time Routines by Category

Show: