简体   繁体   English

GetProcessAffinityMask返回空进程关联

[英]GetProcessAffinityMask returns null process affinity

In a very simple test console application, I tried to get process' affinity mask: 在一个非常简单的测试控制台应用程序中,我尝试获取进程的相似性掩码:

EDIT This code is incorrect. 编辑此代码不正确。 Problem solved. 问题解决了。 Please check comments and validated answer. 请检查评论和经过验证的答案。

#include <cstdlib>
#include <cstdio>
#include <windows.h>

int main()
{
    while (1)
    {
        DWORD dwProcessAffinityMask = 0;
        DWORD dwSystemAffinityMask = 0;

        BOOL res = GetProcessAffinityMask(
            GetCurrentProcess(),
            (PDWORD_PTR)&dwProcessAffinityMask,
            (PDWORD_PTR)&dwSystemAffinityMask);

        printf("%d 0x%X 0x%X\n",
            res,
            dwProcessAffinityMask,
            dwSystemAffinityMask);

        Sleep(1000);
    }

    return 0;
}

Here is the output (64-bit executable, 64-bit system, meaning I do not fall into the WoW64 special case): 这是输出(64位可执行文件,64位系统,这意味着我不属于WoW64特例):

1 0x0 0x3
1 0x0 0x3
...

Running on my laptop, which has a 2 cores CPU, the resulting system's mask looks correct. 在具有2核CPU的笔记本电脑上运行,生成的系统掩码看起来正确。 But I don't understand the meaning of the dwProcessAffinityMask value I get here. 但是我不明白我在这里得到的dwProcessAffinityMask值的含义。 Just for the sake of it, I also tried to toy around with the Task Manager by changing the process' affinity mask but the output remains the same. 仅出于此目的,我还尝试通过更改进程的亲和力掩码来与任务管理器配合使用,但输出保持不变。

This behavior doesn't seem to be documented . 似乎没有记录这种行为。

Pass the address of DWORD_PTR variables rather than DWORD variables. 传递DWORD_PTR变量而不是DWORD变量的地址。

DWORD_PTR dwProcessAffinityMask;
DWORD_PTR dwSystemAffinityMask;

And remove those casts. 并删除那些演员。 They were a clear indication of what was wrong. 它们清楚地表明出了什么问题。 When the compiler reports that you are passing parameters whose types don't match, correct the types rather than suppressing the error. 当编译器报告您正在传递类型不匹配的参数时,请更正类型而不是抑制错误。 The compiler already told you what was wrong, you just need to learn how to interpret its messages. 编译器已经告诉您出了什么问题,您只需要学习如何解释其消息即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM