Share via


TerminateProcess

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

BOOL TerminateProcess(
  HANDLE hProcess, 
  DWORD uExitCode
);

Parameters

  • hProcess
    [in] Handle to the process to terminate.
  • uExitCode
    [in] Specifies the exit code for the process and for all threads terminated as a result of this call. Use the GetExitCodeProcess function to retrieve the process's exit value. Use the GetExitCodeThread function to retrieve a thread's exit value.

Return Values

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

Remarks

This function is used to unconditionally cause a process to exit. Use it only in extreme circumstances.

It causes all threads within a process to terminate, and causes a process to exit, and will notify each DLL that the process is terminating.

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

  1. All object handles that were 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 that had been waiting for the process to terminate.
  4. The states of all threads of the process become signaled, satisfying threads that had been 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

OS Versions: Windows CE 1.0 and later.
Header: Winbase.h.
Link Library: Coredll.lib.

See Also

GetExitCodeProcess | GetExitCodeThread

Last updated on Wednesday, April 13, 2005

© 2005 Microsoft Corporation. All rights reserved.