Windows API Reference

TerminateProcess

Synopsis

#include <windows.h>
BOOL WINAPI TerminateProcess(
    _In_ HANDLE hProcess,
    _In_ UINT   uExitCode
);

Parameters

ParameterDescription
hProcess Handle to the process to be terminated. The handle must have PROCESS_TERMINATE access.
uExitCode Exit code to be used by the terminated process. This value is available to other processes through GetExitCodeProcess.

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

Example

#include <windows.h> #include <stdio.h> int main(void) { DWORD pid = 1234; // PID of the process to terminate HANDLE hProc = OpenProcess(PROCESS_TERMINATE, FALSE, pid); if (!hProc) { printf("OpenProcess failed: %lu\n", GetLastError()); return 1; } if (!TerminateProcess(hProc, 0)) { printf("TerminateProcess failed: %lu\n", GetLastError()); } else { printf("Process %lu terminated.\n", pid); } CloseHandle(hProc); return 0; }

See Also