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;