다음을 통해 공유


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

.NET Framework equivalent

abort

Abort process without flushing buffers or calling functions registered by atexit and _onexit

Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.

assert

Test for logic error

System::Diagnostics::Debug::Assert

_ASSERT, _ASSERTE macros

Similar to assert, but only available in the debug versions of the run-time libraries

System::Diagnostics::Debug::Assert

atexit

Schedule routines for execution at program termination

System::Diagnostics::Process::Exited

_beginthread, _beginthreadex

Create a new thread on a Windows operating system process

System::Threading::Thread::Start

_cexit

Perform exit termination procedures (such as flushing buffers), then return control to calling program without terminating process

System::Diagnostics::Process::CloseMainWindow

_c_exit

Perform _exit termination procedures, then return control to calling program without terminating process

System::Diagnostics::Process::CloseMainWindow

_cwait

Wait until another process terminates

System::Diagnostics::Process::WaitForExit

_endthread, _endthreadex

Terminate a Windows operating system thread

Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.

_execl, _wexecl

Execute new process with argument list

System::Diagnostics::Process Class, System::Diagnostics::ProcessStartInfo Class

_execle, _wexecle

Execute new process with argument list and given environment

System::Diagnostics::Process Class, System::Diagnostics::ProcessStartInfo Class

_execlp, _wexeclp

Execute new process using PATH variable and argument list

System::Diagnostics::Process Class, System::Diagnostics::ProcessStartInfo Class

_execlpe, _wexeclpe

Execute new process using PATH variable, given environment, and argument list

System::Diagnostics::Process Class, System::Diagnostics::ProcessStartInfo Class

_execv, _wexecv

Execute new process with argument array

System::Diagnostics::Process Class, System::Diagnostics::ProcessStartInfo Class

_execve, _wexecve

Execute new process with argument array and given environment

System::Diagnostics::Process Class, System::Diagnostics::ProcessStartInfo Class

_execvp, _wexecvp

Execute new process using PATH variable and argument array

System::Diagnostics::Process Class, System::Diagnostics::ProcessStartInfo Class

_execvpe, _wexecvpe

Execute new process using PATH variable, given environment, and argument array

System::Diagnostics::Process Class, System::Diagnostics::ProcessStartInfo Class

exit

Call functions registered by atexit and _onexit, flush all buffers, close all open files, and terminate process

System::Diagnostics::Process::Kill

_exit

Terminate process immediately without calling atexit or _onexit or flushing buffers

System::Diagnostics::Process::Kill

getenv, _wgetenv, getenv_s, _wgetenv_s

Get value of environment variable

System::Environment::GetEnvironmentVariable

_getpid

Get process ID number

System::Diagnostics::Process::Id

longjmp

Restore saved stack environment; use it to execute a nonlocal goto

Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.

_onexit

Schedule routines for execution at program termination; use for compatibility with Microsoft C/C++ version 7.0 and earlier

System::Diagnostics::Process::Exited

_pclose

Wait for new command processor and close stream on associated pipe

Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.

perror, _wperror

Print error message

Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.

_pipe

Create pipe for reading and writing

Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.

_popen, _wpopen

Create pipe and execute command

Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.

_putenv, _wputenv, _putenv_s, _wputenv_s

Add or change value of environment variable

Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.

raise

Send signal to calling process

Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.

setjmp

Save stack environment; use to execute non local goto

Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.

signal

Handle interrupt signal

Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.

_spawnl, _wspawnl

Create and execute new process with specified argument list

System::Diagnostics::Process Class, System::Diagnostics::ProcessStartInfo Class

_spawnle, _wspawnle

Create and execute new process with specified argument list and environment

System::Diagnostics::Process Class, System::Diagnostics::ProcessStartInfo Class

_spawnlp, _wspawnlp

Create and execute new process using PATH variable and specified argument list

System::Diagnostics::Process Class, System::Diagnostics::ProcessStartInfo Class

_spawnlpe, _wspawnlpe

Create and execute new process using PATH variable, specified environment, and argument list

System::Diagnostics::Process Class, System::Diagnostics::ProcessStartInfo Class

_spawnv, _wspawnv

Create and execute new process with specified argument array

System::Diagnostics::Process Class, System::Diagnostics::ProcessStartInfo Class

_spawnve, _wspawnve

Create and execute new process with specified environment and argument array

System::Diagnostics::Process Class, System::Diagnostics::ProcessStartInfo Class

_spawnvp, _wspawnvp

Create and execute new process using PATH variable and specified argument array

System::Diagnostics::Process Class, System::Diagnostics::ProcessStartInfo Class

_spawnvpe, _wspawnvpe

Create and execute new process using PATH variable, specified environment, and argument array

System::Diagnostics::Process Class, System::Diagnostics::ProcessStartInfo Class

system, _wsystem

Execute operating-system command

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

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

See Also

Reference

Run-Time Routines by Category