Home>Article>Operation and Maintenance> How to check how many CPUs there are in Linux
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".
#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.
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.
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.
Similarly, use grep -c 'processor' /proc/cpuinfo to count the number of CPUs.
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
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!