SetProcessAffinityMask function

Sets a processor affinity mask for the threads of the specified process.

Syntax

BOOL SetProcessAffinityMask(
  HANDLE    hProcess,
  DWORD_PTR dwProcessAffinityMask
);

Parameters

hProcess

A handle to the process whose affinity mask is to be set. This handle must have the PROCESS_SET_INFORMATION access right. For more information, see Process Security and Access Rights.

dwProcessAffinityMask

The affinity mask for the threads of the process.

On a system with more than 64 processors, the affinity mask must specify processors in a single processor group.

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.

If the process affinity mask requests a processor that is not configured in the system, the last error code is ERROR_INVALID_PARAMETER.

On a system with more than 64 processors, if the calling process contains threads in more than one processor group, the last error code is ERROR_INVALID_PARAMETER.

Remarks

A process affinity mask is a bit vector in which each bit represents a logical processor on which the threads of the process are allowed to run. The value of the process affinity mask must be a subset of the system affinity mask values obtained by the GetProcessAffinityMask function. A process is only allowed to run on the processors configured into a system. Therefore, the process affinity mask cannot specify a 1 bit for a processor when the system affinity mask specifies a 0 bit for that processor.

Process affinity is inherited by any child process or newly instantiated local process.

Do not call SetProcessAffinityMask in a DLL that may be called by processes other than your own.

On a system with more than 64 processors, the SetProcessAffinityMask function can be used to set the process affinity mask only for processes with threads in a single processor group. Use the SetThreadAffinityMask function to set the affinity mask for individual threads in multiple groups. This effectively changes the group assignment of the process.

Requirements

   
Windows version Windows XP [desktop apps | UWP apps] Windows Server 2003 [desktop apps | UWP apps]
Target Platform Windows
Header winbase.h (include Windows.h)
Library Kernel32.lib
DLL Kernel32.dll

See Also

CreateProcess

GetProcessAffinityMask

Multiple Processors

Process and Thread Functions

Processes

Processor Groups

SetThreadAffinityMask