TerminateProcess

  BOOL TerminateProcess(hProcess, uExitCode)    
  HANDLE hProcess;    
  UINT uExitCode;    

A process and all of its threads may be terminated using TerminateProcess.

Parameters

hProcess

Supplies a handle to the process to terminate. The handle must have been created with PROCESS_TERMINATE access.

uExitCode

Supplies the termination status for each thread in the process.

Return Value

The return value is TRUE if the function is successful. Otherwise, it is FALSE in which case extended error information is available from the GetLastError function.

TerminateProcess is used to cause all of the threads within a process to terminate.

While TerminateProcess will cause all threads within a process to terminate, and will cause an application to exit, it does not notify DLLs that the process is attached to that the process is terminating. TerminateProcess is used to unconditionally cause a process to exit. It should only be used in extreme circumstances. The state of global data maintained by DLLs may be compromised if TerminateProcess is used rather that ExitProcess.

Once all of the threads have terminated, the process attains a state of signaled satisfying any waits on the process. The process's termination status is updated from its initial value of STATUS_PENDING to the termination status of the last thread in the process to terminate (usually this is the same value as the TerminationStatus parameter). Terminating a process does not remove a process from the system. It simply causes all of the threads in the process to terminate their execution, and causes all of the object handles opened by the process to be closed. The process is not removed from the system until the last handle to the process is closed.

See Also

ExitProcess, OpenProcess