TerminateProcess function
Terminates the specified process and all of its threads.
Syntax
BOOL WINAPI TerminateProcess( _In_ HANDLE hProcess, _In_ UINT uExitCode );
Parameters
- hProcess [in]
-
A handle to the process to be terminated.
The handle must have the PROCESS_TERMINATE access right. For more information, see Process Security and Access Rights.
- uExitCode [in]
-
The exit code to be used by the process and threads terminated as a result of this call. Use the GetExitCodeProcess function to retrieve a process's exit value. Use the GetExitCodeThread function to retrieve a thread's exit value.
Return value
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError.
Remarks
The TerminateProcess function is used to unconditionally cause a process to exit. The state of global data maintained by dynamic-link libraries (DLLs) may be compromised if TerminateProcess is used rather than ExitProcess.
This function stops execution of all threads within the process and requests cancellation of all pending I/O. The terminated process cannot exit until all pending I/O has been completed or canceled. When a process terminates, its kernel object is not destroyed until all processes that have open handles to the process have released those handles.
TerminateProcess is asynchronous; it initiates termination and returns immediately. If you need to be sure the process has terminated, call the WaitForSingleObject function with a handle to the process.
A process cannot prevent itself from being terminated.
Requirements
|
Minimum supported client |
Windows XP [desktop apps | Windows Store apps] |
|---|---|
|
Minimum supported server |
Windows Server 2003 [desktop apps | Windows Store apps] |
|
Header |
|
|
Library |
|
|
DLL |
|
See also
- ExitProcess
- OpenProcess
- GetExitCodeProcess
- GetExitCodeThread
- Process and Thread Functions
- Processes
- Terminating a Process