Windows Win32 API API Reference Processthreadsapi

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

NameTypeDescription
hProcessHANDLEHandle to the process whose affinity mask is to be retrieved. The handle must have PROCESS_QUERY_INFORMATION access.
lpProcessAffinityMaskPDWORD_PTRPointer to a variable that receives the process affinity mask.
lpSystemAffinityMaskPDWORD_PTRPointer 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

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;
}

See Also