TerminateProcess
The TerminateProcess
function terminates the calling process or the specified process.
On this page
Function Prototype
BOOL TerminateProcess(
HANDLE hProcess,
UINT uExitCode
);
Parameters
Parameter | Description |
---|---|
hProcess |
A handle to the process to be terminated. This parameter can be an access-right mask, or 0. If this parameter is the current process, the process terminates without calling any C++ destructors or functions that are called by the C runtime of your DLL. To terminate another process, the calling process must have the |
uExitCode |
The exit code for the process. Use the macros |
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 terminate a process. When a process is terminated, the system performs the following actions:
- All threads in the process are terminated.
- The process's address space is decommitted.
- The process's handle table is closed.
- The process object is freed.
The system does not call the destructors for C++ objects or the atexit
functions.
To terminate the current process, use the GetCurrentProcess
function to get a pseudohandle to the current process and pass it to TerminateProcess
.
Important
Use TerminateProcess
with caution. Terminating a process abruptly can lead to data loss or corruption if the process has unsaved data or is in the middle of a critical operation.
Note
The system may create a new process that inherits the handle to the terminated process. For example, if you terminate process A, and process B subsequently creates a process C and inherits the handle to process A, the handle to process A will be closed. If you need to terminate a process, you should do so only after closing all handles to that process.
Requirements
Name | Value |
---|---|
Minimum supported client | Windows 2000 Professional [desktop apps only] |
Minimum supported server | Windows 2000 Server [desktop apps only] |
Header | winbase.h (include windows.h ) |
Library | Kernel32.lib |
DLL | Kernel32.dll |