This section provides in-depth documentation on the concept of processes within the Microsoft Windows operating system. A process is an instance of a running program. Each process has its own virtual address space, system resources (such as file handles and registry keys), and security context.
The Windows API provides a rich set of functions for managing processes. These include:
The primary functions for creating a new process are CreateProcess
and CreateProcessAsUser
. Termination can be initiated via TerminateProcess
or by the process itself calling ExitProcess
.
HANDLE hProcess = NULL;
PROCESS_INFORMATION piProcInfo;
STARTUPINFO siStartInfo;
ZeroMemory(&siStartInfo, sizeof(siStartInfo));
siStartInfo.cb = sizeof(STARTUPINFO);
// Create the child process.
if (CreateProcess(
NULL, // Module name.
"notepad.exe", // Command line.
NULL, // Process handle not inheritable.
NULL, // Thread handle not inheritable.
FALSE, // Set handle inheritance to FALSE.
0, // No creation flags.
NULL, // Use parent's environment block.
NULL, // Use parent's starting directory.
&siStartInfo, // Pointer to STARTUPINFO structure.
&piProcInfo)) // Pointer to PROCESS_INFORMATION structure.
{
// The process was created.
printf("Process created successfully.\n");
// Wait until child process exits.
WaitForSingleObject(piProcInfo.hProcess, INFINITE);
// Close process and thread handles.
CloseHandle(piProcInfo.hProcess);
CloseHandle(piProcInfo.hThread);
}
else
{
printf("CreateProcess failed (%d).\n", GetLastError());
}
You can retrieve detailed information about a process using functions like GetProcessId
, GetExitCodeProcess
, and by querying process performance data via performance counters or WMI.
Processes run with specific security contexts, defined by their associated access token. Understanding process privileges is crucial for developing secure applications.
Processes transition through various states during their execution, including: