gogoWebsite

How to check CPU cores in Linux

Updated to 6 months ago

In Linux, you can use cat /proc/cpuinfo| grep "cpu cores"| uniq to see the number of CPU cores, i.e. the number of cores in each physical CPU.

I. Introduction to knowledge points

1. cpu information is recorded in /proc/cpuinfo;

2, Top in Linux is equivalent to the task manager under the Win system, which can also be used to query;

3. Total CPU cores = number of physical CPUs * number of cores per physical CPU;

4. Total logical CPUs = number of physical CPUs * number of cores per physical CPU * number of hyperthreads;

II. Query commands
 

# View CPU information (model number)
[root@ecsnode-no ~]# cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c
     16 Intel Core Processor (Skylake)

# View the number of physical CPUs
[root@ecsnode-no ~]# cat /proc/cpuinfo | grep "physical id" | sort | uniq | wc -l
1

# View the number of cores per physical CPU.
[root@ecsnode-no ~]# cat /proc/cpuinfo | grep "cpu cores" | uniq
cpu cores : 8

# Check the number of logical CPUs
[root@ecsnode-no ~]# cat /proc/cpuinfo | grep "processor" | wc -l
16

What does all this mean, then look at the CPU architecture

Multiple physical CPUs, with CPUs communicating over a bus, are less efficient, as follows:

 

Multi-core CPUs, where different cores communicate via L2 cache, and storage and peripherals communicate with the CPU via buses as follows:

Multi-Core Hyper-Threading,Each core has two logical processing units and the two processing units share the resources of one core as follows:

From the result of the above execution, this linux machine has 1 physical cpu, this cpu has 8 cores and each core has 2 hyperthreads, so this machine has 1*8*2=16 logical cpus.

Of course we can use the top command and press keypad 1 to see the number of logical CPUs as shown below: