Process Management Overview
Windows provides a rich set of functions to create, query, and control processes. Below is a quick reference to the most common APIs.
| Function | Header | Description | Link |
|---|---|---|---|
| CreateProcess | Windows.h | Creates a new process and its primary thread. | Details |
| OpenProcess | Windows.h | Opens an existing process with specified access. | Details |
| TerminateProcess | Windows.h | Ends a process and all of its threads. | Details |
| GetCurrentProcessId | Processthreadsapi.h | Retrieves the process identifier of the calling process. | Details |
| CreateToolhelp32Snapshot | Tlhelp32.h | Creates a snapshot of the specified processes, as well as the heaps, modules, and threads used by these processes. | Details |
Sample: Creating a Process
#include <windows.h>
int main() {
STARTUPINFO si = { sizeof(si) };
PROCESS_INFORMATION pi;
if (CreateProcess(L"C:\\Windows\\System32\\notepad.exe",
NULL, NULL, NULL, FALSE, 0, NULL, NULL,
&si, &pi)) {
// Wait until child process exits.
WaitForSingleObject(pi.hProcess, INFINITE);
CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);
}
return 0;
}