简体   繁体   English

Win32 C ++:获取进程CPU关联性?

[英]Win32 c++: Get process CPU affinity?

I need to query the CPU affinity of my program and find how many CPUs from the total number of CPUs available to the system are assigned to it. 我需要查询程序的CPU相似性,并从系统可用的CPU总数中找到分配给它的CPU数量。

std::thread::hardware_concurrency() returns a value that doesn't reflect affinity. std::thread::hardware_concurrency()返回一个不反映亲和力的值。 Is there a (fast) way to query process affinity? 有(快速)查询过程亲和力的方法吗?

Seems like this is working: 看起来像这样工作:

int getAffinityCount()
{
    DWORD64 dwProcessAffinity, dwSystemAffinity;
    GetProcessAffinityMask(GetCurrentProcess(), &dwProcessAffinity, &dwSystemAffinity);
    return __popcnt64(dwProcessAffinity);
}

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

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