Sometimes we need to find CPU related information in a Linux system, such as CPU vendor, number of CPU cores, number of threads, CPU clock speed, available CPU cache and many more.
You can easily check CPU info in Linux with few commands, there are many GUI apps for this as well, like kInfocenter for KDE or gtk based HardInfo app.
We are going to get those results from the /proc/cpuinfo file, lscpu and dmidecode commands. Lets start,
Contents
Check CPU info from the /proc/cpuinfo file in Linux
This file is generated by the kernel during boot, contains some information about the CPU in a human readable format. This file could be used in different ways to know CPU related info.
The easiest method is use the cat command and read it, or use the grep command to directly print the filtered results, no root privileges required.
cat /proc/cpuinfo
Now being more specific, filter the output of different commands and print exactly what we need, also use all three sources commands when needed to check cpu info in Linux.
Find CPU vendor and model number
- With the lscpu command
lscpu | grep -iE 'model name|vendor id'
Vendor ID: GenuineIntel Model name: Intel(R) Core(TM) i5-2410M CPU @ 2.30GHz
- From the /proc/cpuinfo file
grep -i 'vendor' /proc/cpuinfo | uniq vendor_id : GenuineIntel
grep -i 'model name' /proc/cpuinfo | uniq model name : Intel(R) Core(TM) i5-2410M CPU @ 2.30GHz
- With the dmidecode command
sudo dmidecode -t 4 | grep -i 'Manufacturer:|Version:'
Manufacturer: Intel(R) Corporation Version: Intel(R) Core(TM) i5-2410M CPU @ 2.30GHz
Find number of CPU socket, cores, threads and NUMA nodes
you can use any method mentioned above to find out this, I'm using the lscpu command here. All grep filtering parameters are merged into one, use only whatever you need.
lscpu | grep -iE 'Thread(s) per core:|Core(s) per socket:|Socket(s):|NUMA node(s):'
Thread(s) per core: 2 Core(s) per socket: 2 Socket(s): 1 NUMA node(s): 1
You need to append each brackets with one backslash for proper functioning of grep command. If you are not familiar with what is NUMA, read this NUMA wiki article.
You can easily observe the hyper threading capability of the CPU from the threads per core count, here it's 2 threads per core.
While building some software form source in Linux with make , you probably use the -j flag for faster parallel compilation, you could automatically assign number of CPUs with this command,
nproc
Or use the grep command like bellow
grep -c "^processor" /proc/cpuinfo
You may create an alias or use it directly like bellow
make -j $(grep -c "^processor" /proc/cpuinfo)
Find CPU architecture, CPU endianness and supported operation modes
To know your CPU architecture, it supports 64 bit OS or not, and CPU endianness , use the lscpu command.
lscpu | grep -iE 'Architecture:|CPU op-mode(s):|Byte Order:'
Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Byte Order: Little Endian
Find current, maximum and minimum CPU frequency
To find out current CPU frequency, use the /proc/cmdline file to get per thread frequency,
grep -i mhz /proc/cpuinfo
To check the current frequency and maximum/minimum frequency supported by the CPU use the lscpu command.
lscpu | grep -iE 'CPU MHz|CPU max MHz|CPU min MHz'
CPU MHz: 800.328 CPU max MHz: 2900.0000 CPU min MHz: 800.0000
You can use the CoreFreq application on Linux to check CPU usage and more.
Check CPU cache memory
You can use the lscpu
command to find available L1, L2 and L3 cache memory.
lscpu | grep 'cache'
Another method could be
grep -i 'cache size' /proc/cpuinfo | uniq
The hwloc -ls
command displays the CPU cache memory in a nice picture, it's a GUI app, more about hwloc-ls bellow.
Check CPU microcode version
CPU microcode could be called the firmware of the CPU, to enhance it's usability and add new features. To check CPU microcode version use,
grep -i microcode /proc/cpuinfo | uniq
An alternative method could be with dmesg
dmesg | grep -i microcodr
Read more about microcode, how to update CPU microcode in Linux.
GUI apps to find CPU info Linux
There are lots of them, KInfocenter, HardInfo, cpu-g, hwloc and so on, I'm going to discus about Hardinfo and hwloc .
Here's how to install Hardinfo in any Debian based distro with apt-get.
sudo apt-get install hardinfo
You could run it from a terminal emulator by running the hardinfo
command,or open up from the menu, usually named as System Profiler and Benchmark.The HardInfo interface is quite easy to understand, explore through different options to discover more.
Now the hwloc, install it with apt-get in any Debian based distro,
sudo apt-get install hwloc
Run hwloc-ls or lstopo , this will open up a GUI window, displaying a nice image like bellow.A great visual representation of the CPU information and how some devices are connected through the PCI-E bus.
Conclusion
So, that;'s it, how you could find CPU info in Linux, strip down the commands according to your need while using within a shell script. I hope this tutorial is informative and easy to understand.
If you have any suggestion or question, just drop a comment, also don't forget to share this tutorial if you find it useful.
Leave a Reply