共用方式為


TerminateProcess

A version of this page is also available for

Windows Embedded CE 6.0 R3

4/8/2010

This function closes the specified process and all of its threads.

Syntax

BOOL TerminateProcess(
  HANDLE hProcess,
  DWORD uExitCode
);

Parameters

  • hProcess
    [in] Handle to the process to terminate. This is a handle returned from OpenProcess.
  • uExitCode
    [in] Specifies the exit code for the process and for all threads terminated as a result of this call.

    To retrieve the process's exit value, use the GetExitCodeProcess function.

    To retrieve a thread's exit value, use the GetExitCodeThread function.

Return Value

Nonzero indicates success. Zero indicates failure. To get extended error information, call GetLastError.

When the system is very busy, TerminateProcess may fail due to timeout. In this case, ERROR_BUSY is set for the last error.

Remarks

This function is used to unconditionally cause a process to exit.

Use this function only in extreme circumstances.

This function causes all threads within a process to terminate, causes a process to exit, and notifies each DLL that the process is terminating.

The following list shows what occurs when a process is terminated:

  1. All object handles opened by the process are closed.
  2. All threads in the process terminate their execution.
  3. The state of the process object becomes signaled, satisfying threads waiting for the process to terminate.
  4. The states of all threads of the process become signaled, satisfying threads waiting for the threads to terminate.
  5. The termination status of the process changes from STILL_ACTIVE to the exit value of the process.

Terminating a process does not necessarily remove the process object from the system.

A process object is deleted when the last handle to the process is closed.

Requirements

Header winbase.h
Library coredll.lib
Windows Embedded CE Windows CE 1.0 and later
Windows Mobile Windows Mobile Version 5.0 and later

See Also

Reference

Process and Thread Functions
GetExitCodeProcess
GetExitCodeThread
OpenProcess