开发者

Is this the right way to get the grand total of processors with WMI on a multi-cpu system?

开发者 https://www.devze.com 2022-12-25 10:16 出处:网络
I don\'t have access to a multi-socketed computer, so I am unsure if the follo开发者_开发问答wing will get the grand total of processors and logical processors.I assume ManagementObjectSearcher will r

I don't have access to a multi-socketed computer, so I am unsure if the follo开发者_开发问答wing will get the grand total of processors and logical processors. I assume ManagementObjectSearcher will return an instance for each socketed CPU and I just keep a running total?

int totalCPUs = 0;
int totalLogicalCPUs = 0;

ManagementObjectSearcher mos = new ManagementObjectSearcher("Select * from Win32_ComputerSystem");
foreach (var mo in mos.Get())
{
    string num = mo.Properties["NumberOfProcessors"].Value.ToString();
    totalCPUs += Convert.ToInt32(num);


    num = mo.Properties["NumberOfLogicalProcessors"].Value.ToString();
    totalLogicalCPUs += Convert.ToInt32(num);
}


It will only return 1 instance of Win32_ComputerSystem. From the documentation:

If a computer system has two physical processors each containing two logical processors, then the value of NumberOfProcessors is 2 and NumberOfLogicalProcessors is 4. The processors may be multicore or they may be hyperthreading processors.

0

精彩评论

暂无评论...
验证码 换一张
取 消