GetProcessAffinityMask Function
GetProcessAffinityMask Function

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/2000:  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 clientWindows 2000 Professional
Minimum supported serverWindows 2000 Server
HeaderWinbase.h (include Windows.h)
LibraryKernel32.lib
DLLKernel32.dll

See Also

Multiple Processors
Process and Thread Functions
Processes
Processor Groups
SetProcessAffinityMask
SetThreadAffinityMask

Send comments about this topic to Microsoft

Build date: 11/19/2009

Community Content

vb.net syntax
Added by:dmex
<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
C# syntax
Added by:dmex
[DllImport("kernel32.dll", CharSet=CharSet.Auto, SetLastError=true)]
public static extern bool GetProcessAffinityMask(SafeProcessHandle handle, out IntPtr processMask, out IntPtr systemMask);
x64 compile problems!
Added by:GreenCat

DWORD ProcessAffinityMask, SystemAffinityMask;
GetProcessAffinityMask(GetCurrentProcess(), &ProcessAffinityMask, &SystemAffinityMask);

Compiles fine using win32
Compiling using x64

1>ProcessorFrequence.cpp
1>.\ProcessorFrequence.cpp(145) : error C2664: 'GetProcessAffinityMask' : cannot convert parameter 2 from 'DWORD *' to 'PDWORD_PTR'

x64 WinBase.h line 3280

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

stdafx.h is

#pragma once
#include "targetver.h"
#include <stdio.h>
#include <tchar.h>
#include <atlstr.h>
#include <windows.h>
#include <assert.h>
#include <math.h>
#include <intrin.h>


[GreenCat] Cannot you distinguish DWORD * and DWORD_PTR *?
© 2009 Microsoft Corporation. All rights reserved.   Terms of Use | Trademarks | Privacy Statement
Page view tracker
Rate the Lightweight library
x
Lightweight builds on ScriptFree (loband) by adding features you've requested: a SearchBox and default code language selection.
Do you like the SearchBox?
Do you like the tabbed code blocks?
How useful is this topic?
Tell us more.
Thanks
x
You're helping to improve MSDN Online.
Feedback
Switch View
Classic
Lightweight Beta
ScriptFree
Switch View