Home>Article>Operation and Maintenance> How to check how many CPUs there are in Linux

How to check how many CPUs there are in Linux

WBOY
WBOY Original
2022-01-04 11:38:00 24127browse

In Linux, you can use the grep command to check how many CPUs there are. This command is used to find strings that meet the conditions in the file. When this command is used in conjunction with the "/proc/cpuinfo" file, you can query the number of CPUs. Number, the syntax is "grep -c 'processor' /proc/cpuinfo".

How to check how many CPUs there are in Linux

#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.

How to check how many CPUs there are in Linux

First of all, I will show you the situation of 1 CPU. This situation is the simplest.

CPU information is stored in /proc/cpuinfo, as shown in the figure below. The physical id represents the CPU number, the number starts from 0, and cpu cores represents the number of cores. It can be seen that there is 1 core. CPU, that is, the number of CPUs is 1.

How to check how many CPUs there are in Linux

After we know the specific file where the CPU information is stored, we can simply use grep -c 'processor' /proc/cpuinfo to count the number of CPUs.

How to check how many CPUs there are in Linux

The following demonstrates the query situation of multiple CPUs. First check /proc/cpuinfo to see if there is any difference in the cpu information. It can be seen that there are two 4-core CPUs, that is, the number of CPUs is 8.

How to check how many CPUs there are in Linux

Similarly, use grep -c 'processor' /proc/cpuinfo to count the number of CPUs.

How to check how many CPUs there are in Linux

You can also use the following method to query the number of CPUs, cores, and total number of logical CPUs individually.

Note: The total number of logical CPUs = the number of physical CPUs * the number of cores of each physical CPU * the number of hyperthreads

Query the number of CPUs

cat /proc/cpuinfo| grep "physical id"| sort| uniq| wc -l

Query the number of cores:

cat /proc/cpuinfo| grep "cpu cores"| uniq

Query the total number of logical CPUs:

cat /proc/cpuinfo| grep "processor"| wc -l

How to check how many CPUs there are in Linux

Related recommendations: "Linux Video Tutorial"

The above is the detailed content of How to check how many CPUs there are in Linux. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn