这是在多 CPU 系统上获取带有 WMI 的处理器总数的正确方法吗?

发布于 2024-08-27 16:17:39 字数 540 浏览 1 评论 0原文

我无法访问多插槽计算机,因此我不确定以下计算机是否会获得处理器和逻辑处理器的总数。我假设 ManagementObjectSearcher 将为每个插槽的 CPU 返回一个实例,而我只保留运行总数?

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);
}

I don't have access to a multi-socketed computer, so I am unsure if the following 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);
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

饮惑 2024-09-03 16:17:39

它只会返回 1 个 Win32_ComputerSystem 实例。来自文档

如果计算机系统有两个物理处理器,每个处理器包含两个逻辑处理器,则 NumberOfProcessors 的值为 2,NumberOfLogicalProcessors 的值为 4。处理器可能是多核处理器,也可能是超线程处理器。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文