1

I realize I can get the logical processor count by referencing Environment.ProcessorCount but is there a way to get the number of physical processors/cores on a machine using .NET core 2.2? In the .NET Framework, I would use something like the following but I know that isn't available in core due to cross-os support.

var physicalCPUs = 0;
List<string> sockets = new List<string>();
System.Management.ManagementClass mc = new System.Management.ManagementClass("Win32_Processor");
System.Management.ManagementObjectCollection moc = mc.GetInstances();
// Iterate through logical processors
foreach (System.Management.ManagementObject mo in moc)
{
    string socketDesignation = mo.Properties["SocketDesignation"].Value.ToString();
    // We will count the unique SocketDesignations to find the number of physical CPUs in the system.
    if (!sockets.Contains(socketDesignation))
        sockets.Add(socketDesignation);
}
physicalCPUs = sockets.Count;
Geekn
  • 2,650
  • 5
  • 40
  • 80
  • Did you manage to get the number of physical processors (CPU sockets) on .NET Core? – Thinko Oct 21 '19 at 12:32
  • [How to find the Number of physical CPU Cores via .NET Core?](https://stackoverflow.com/q/60755418) is a re-ask of the same thing. – Peter Cordes Mar 19 '20 at 16:59

0 Answers0