GetProcessAffinityMask function (Windows)

Switch View :
ScriptFree
GetProcessAffinityMask function

Applies to: desktop apps only

Retrieves the process affinity mask for the specified process and the system affinity mask for the system.

Syntax

BOOL WINAPI GetProcessAffinityMask(
  __in   HANDLE hProcess,
  __out  PDWORD_PTR lpProcessAffinityMask,
  __out  PDWORD_PTR lpSystemAffinityMask
);

Parameters

hProcess [in]

A handle to the process whose affinity mask is desired.

This handle must have the PROCESS_QUERY_INFORMATION or PROCESS_QUERY_LIMITED_INFORMATION access right. For more information, see Process Security and Access Rights.

Windows Server 2003 and Windows XP:  The handle must have the PROCESS_QUERY_INFORMATION access right.
lpProcessAffinityMask [out]

A pointer to a variable that receives the affinity mask for the specified process.

lpSystemAffinityMask [out]

A pointer to a variable that receives the affinity mask for the system.

Return value

If the function succeeds, the return value is nonzero and the function sets the variables pointed to by lpProcessAffinityMask and lpSystemAffinityMask to the appropriate affinity masks.

On a system with more than 64 processors, if the threads of the calling process are in a single processor group, the function sets the variables pointed to by lpProcessAffinityMask and lpSystemAffinityMask to the process affinity mask and the processor mask of active logical processors for that group. If the calling process contains threads in multiple groups, the function returns zero for both affinity masks.

If the function fails, the return value is zero, and the values of the variables pointed to by lpProcessAffinityMask and lpSystemAffinityMask are undefined. To get extended error information, call GetLastError.

Remarks

A process affinity mask is a bit vector in which each bit represents the processors that a process is allowed to run on. A system affinity mask is a bit vector in which each bit represents the processors that are configured into a system.

A process affinity mask is a subset of the system affinity mask. 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.

Requirements

Minimum supported client

Windows XP

Minimum supported server

Windows Server 2003

Header

WinBase.h (include Windows.h)

Library

Kernel32.lib

DLL

Kernel32.dll

See also

Multiple Processors
Process and Thread Functions
Processes
Processor Groups
SetProcessAffinityMask
SetThreadAffinityMask

 

 

Send comments about this topic to Microsoft

Build date: 3/7/2012

Community Content

Jim Michaels
pointer to fake pointer?
PDWORD_PTR is defined as basically something like an LPDWORD.

ULONG_PTR as an unsigned long. PDWORD_PTR is *ULONG_PTR;  so really it's a *unsigned long; and this is simply like an LPDWORD.

I have no idea what microsoft is up to with this.  is this supposed to be a pointer to a fake pointer?

Carol Buchmiller - MSFT
x64 compile problems!
Cannot distinguish DWORD * and DWORD_PTR *?

[Carol Buchmiller - MSFT: Thanks for your post. You should post questions to the MSDN forums at http://forums.microsoft.com/msdn. You are likely to get an answer more quickly than in Community Content.]

dmex
C# syntax
[DllImport("kernel32.dll", CharSet=CharSet.Auto, SetLastError=true)]
public static extern bool GetProcessAffinityMask(SafeProcessHandle handle, out IntPtr processMask, out IntPtr systemMask);

dmex
vb.net syntax
<DllImport("kernel32.dll", CharSet:=CharSet.Auto, SetLastError:=True)> _
Public Shared Function GetProcessAffinityMask(ByVal handle As SafeProcessHandle, <Out> ByRef processMask As IntPtr, <Out> ByRef systemMask As IntPtr) As Boolean End Function