GetProcessAffinityMask
Overview
Retrieves the process affinity mask for the specified process and the system affinity mask for the system on which the process is running.
Syntax
BOOL GetProcessAffinityMask(
HANDLE hProcess,
PDWORD_PTR lpProcessAffinityMask,
PDWORD_PTR lpSystemAffinityMask
);
Parameters
| Name | Type | Description |
|---|---|---|
| hProcess | HANDLE | Handle to the process whose affinity mask is to be retrieved. The handle must have PROCESS_QUERY_INFORMATION access. |
| lpProcessAffinityMask | PDWORD_PTR | Pointer to a variable that receives the process affinity mask. |
| lpSystemAffinityMask | PDWORD_PTR | Pointer to a variable that receives the system affinity mask. |
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 process affinity mask is a bitmask in which each bit represents a logical processor that the process is allowed to run on.
- The system affinity mask indicates the processors that are configured into the system.
- Use
SetProcessAffinityMaskto change a process's affinity mask. - On systems with more than 64 logical processors, the affinity mask is represented as a
DWORD_PTRarray.
Example
#include <windows.h>
#include <stdio.h>
int main(void)
{
HANDLE hProcess = GetCurrentProcess();
DWORD_PTR processMask, systemMask;
if (GetProcessAffinityMask(hProcess, &processMask, &systemMask))
{
printf("Process Affinity Mask: 0x%I64x\n", (unsigned long long)processMask);
printf("System Affinity Mask : 0x%I64x\n", (unsigned long long)systemMask);
}
else
{
printf("GetProcessAffinityMask failed. Error: %lu\\n", GetLastError());
}
return 0;
}