Introduction: One can obtain the number of CPUs or cores in Linux from the command line. The /proc/cpuinfo file stores CPU and system architecture dependent items, for each supported architecture. You can view /proc/cpuinfo with the help of cat command or grep command/egrep command. This page shows how to use /proc/cpuinfo file and lscpu command to display number of processors on Linux.
How do you check how many CPUs are there in Linux system?
You can use one of the following command to find the number of physical CPU cores including all cores on Linux:
- lscpu command
- cat /proc/cpuinfo
- top or htop command
- nproc command
- hwinfo command
- dmidecode -t processor command
- getconf _NPROCESSORS_ONLN command
Let us see all commands and examples in details.
How to display information about the CPU on Linux
Just run the lscpu command:
$ lscpu
$ lscpu | egrep 'Model name|Socket|Thread|NUMA|CPU\(s\)'
$ lscpu -p
The output clearly indicate that I have:
- CPU model/make: AMD Ryzen 7 1700 Eight-Core Processor
- Socket: Single (1)
- CPU Core: 8
- Thread per core: 2
- Total threads: 16 ( CPU core[8] * Thread per core [2])
Use /proc/cpuinfo to find out how many CPUs are there in Linux
The lscpu command gathers CPU architecture information from sysfs, /proc/cpuinfo and other sources. To view use the cat command and more command as follows:
$ cat /proc/cpuinfo
OR
$ more /proc/cpuinfo
Let us print cpu thread count:
$ echo "CPU threads: $(grep -c processor /proc/cpuinfo)"
$ grep 'cpu cores' /proc/cpuinfo | uniq
Run top or htop command to obtain the number of CPUs/cores in Linux
Simply run the following command and hit ‘1’:
$ top
Another option is to run lovely htop:
$ htop
How do I Find Out Linux CPU Utilization?
Execute nproc print the number of CPUs available on Linux
Let us print the number of installed processors on your system i.e core count:
$ nproc --all
$ echo "Threads/core: $(nproc --all)"
Sample outputs:
Threads/core: 16
How to probe for CPU/core on Linux using hwinfo command
$ hwinfo --cpu --short ## short info ##
$ hwinfo --cpu ## detailed info on CPUs ##
Linux display CPU core with getconf _NPROCESSORS_ONLN command
One can query Linux system configuration variables with getconf command:
$ getconf _NPROCESSORS_ONLN
$ echo "Number of CPU/cores online at $HOSTNAME: $(getconf _NPROCESSORS_ONLN)"
Sample outputs:
Number of CPU/cores online at nixcraft-asus.nixcraft.com: 16
dmidecode -t processor command
You can use get BIOS and hardware information with dmidecode command (DMI table decoder) on Linux. To find out how many CPUs are there in Linux system, run:
$ sudo dmidecode -t 4
$ sudo dmidecode -t 4 | egrep -i 'core (count|enabled)|thread count|Version'
Linux Setting processor affinity for a certain task or process
Here is a quick video demo of lscpu and other commands:
Conclusion
You learned how to display information about the CPU architecture, core, threads, CPU version/model, vendor and other information using various Linux command line options.
- Check how many CPUs are there in Linux system
- Linux Find If Processor (CPU) is 64 bit / 32 bit [long mode ~ lm]
- Linux Find Out CPU Architecture Information
- Linux Hotplug a CPU and Disable CPU Cores At Run Time
- Linux Command To Find the System Configuration And Hardware Information
- How To Read CPUID Instruction For Each CPU on Linux With x86info and cpuid Commands
- Linux Display CPU Information Number of CPUs and Their Speed
- Linux detect or find out a dual-core cpu
- Stress Test CPU and Memory (VM) On a Linux / Unix With Stress-ng
- Linux Find Out If CPU Support Intel VT/AMD-V Virtualization For KVM
- Linux display each multiple SMP CPU processors utilization individually
- Linux Find Number of CPU Cores Command
- Linux Read CPU Temperature Sensor Chip Data Including Voltage and Fan Speed With lm-sensors
🐧 1 comment so far... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |
Nice examples. Suggest removing the $ in the examples so that the student does not copy and paste $