Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Question about Environment.ProcessorCount

I am curious as to what the .NET property Environment.ProcessorCount actually returns. Does it return the number of cores, the number of processors or both? If my computer had 2 processors, each with 4 cores, would Environment.ProcessorCount return 2, 4, or 8?

like image 894
Icemanind Avatar asked Nov 22 '09 20:11

Icemanind


People also ask

What is the use of have environment processorcount?

Have Environment.ProcessorCount return a value that represents an appropriate level of parallelism that may be used in the process based on affinitization and CPU resource limits Have the property return a consistent value in comparable relevant configuration between Windows and Linux

What is the difference between the--CPUs and--processorcount behavior?

Current behavior: Environment.ProcessorCount returns the rounded up decimal value presented via --cpus. For example --cpus 0.4 will result in a return value of 1. Proposed OPT-IN behavior: Environment.ProcessorCount returns the value specified by an environment variable.

Does it reflect changes in environment settings while the process is running?

It does not reflect changes in the environment settings while the process is running. For more information about processor groups and logical processors, see Processor Groups. Defines a lock that supports single writers and multiple readers.

What is the use of the number of processors in Windows?

On Windows, the property returns the number of processors configured in the system and ignores the affinity mask. The property is often used to determine the amount of parallelism to use in the process, and it has been observed that not limiting the property's value based on affinitization can lead to worse performance.


1 Answers

It will return the NUMBER_OF_PROCESSORS environment variable. (see MSDN)

This will equal the number of logical cores - i.e. if you have a HT enabled single core processor, it will return 2.

In your case, it should return 8.

It will be the same number as the number of CPU utilization graphs you will see in task manager.

like image 190
Marek Avatar answered Sep 23 '22 14:09

Marek