Linux Display CPU Information Number of CPUs and Their Speed
Tutorial details | |
---|---|
Difficulty level | Intermediate |
Root privileges | No |
Requirements | /proc, ls, and lscpu |
Est. reading time | N/A |
You can also use the command called lscpu to display information on CPU architecture on modern Linux distributions.
Task: Display the number of processors in Linux
You need to use the /proc/cpuinfo file. This is a collection of CPU and system architecture dependent items, for each supported architecture a different list. Two common entries are processor which gives CPU number and bogomips; a system constant that is calculated during kernel initialization. SMP machines have information for each CPU. Type the following command:
$ more /proc/cpuinfo
OR
$ cat /proc/cpuinfo
OR
$ less /proc/cpuinfo
Sample outputs:
- No ads and tracking
- In-depth guides for developers and sysadmins at Opensourceflare✨
- Join my Patreon to support independent content creators and start reading latest guides:
- How to set up Redis sentinel cluster on Ubuntu or Debian Linux
- How To Set Up SSH Keys With YubiKey as two-factor authentication (U2F/FIDO2)
- How to set up Mariadb Galera cluster on Ubuntu or Debian Linux
- A podman tutorial for beginners – part I (run Linux containers without Docker and in daemonless mode)
- How to protect Linux against rogue USB devices using USBGuard
Join Patreon ➔
You can narrow down the output with the following commands, to display number of processors in the system:
$ grep processor /proc/cpuinfo
Say hello to lscpu
The lscpu command is CPU architecture information helper and can be found under Fedora Linux / RHEL / CentOS v6+ / Debian Linux v6+ and many other latest distro includes this command.
$ lscpu
Sample outputs:
Warning : lscput command has bug and sometimes in Xen Dom0 kernel reports wrong data. So please use /proc/cpuinfo for verification purpose.
Video demo: /proc/cpuinfo and lscpu command
See the following video demo:
See also:
🐧 Get the latest tutorials on Linux, Open Source & DevOps via
Category | List of Unix and Linux commands |
---|---|
Documentation | help • mandb • man • pinfo |
Disk space analyzers | df • duf • ncdu • pydf |
File Management | cat • cp • less • mkdir • more • tree |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Linux Desktop Apps | Skype • Spotify • VLC 3 |
Modern utilities | bat • exa |
Network Utilities | NetHogs • 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 • glances • gtop • jobs • killall • kill • pidof • pstree • pwdx • time • vtop |
Searching | ag • grep • whereis • which |
Shell builtins | compgen • echo • printf |
Text processing | cut • rev |
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 |
Comments on this entry are closed.
this works, but you have to pay attention, cause not every time it shows correct info. For example i have 2x intel xeon quad core. cpuinfo shows 16 processors.
LOL funny answer, but the programs work fine for me. Thanks cyberciti.
You actually have 16 cores, 8 phsical, 8 logical, Xeon processors have 2 threads per physical core, so, if you have Quad core, it will show 8 cores 🙂
you have 16 virtual processors total…that is correct
2 quads but each of the these physical processors implement hyperthreading
It makes you wonder why he/she even needs two Xeons
Maybe HE/SHE doesn’t but the company DOES and they are not familiar with that.
ASS*U*ME
For just the number of CPUs and speed, this may be simpler.
cat /proc/cpuinfo | grep MHz
I have a VPS and am trying to figure out wether I should user prefork.c or worker.c (better with multiple processors I believe) with apache. I’m trying to decide this based on the number of processors I have. However, this is the info I’m getting from the command mentioned above:
processor : 0
vendor_id : GenuineIntel
cpu family : 15
model : 4
model name : Intel(R) Xeon(TM) CPU 2.80GHz
stepping : 1
cpu MHz : 2798.083
cache size : 1024 KB
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 5
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss nx constant_tsc up pebs bts p
ni
bogomips : 5630.31
clflush size : 64
power management:
Any thoughts on how to get the info that I’m looking for?
Whether you have multiple processors or not doesn’t affect your choice between worker and prefork. They both will make full use of all your processors.
Worker uses multiple threads within a unix process, so is more efficient. Prefork uses multiple processes, so you have extra overhead.
There is no good reason to use prefork at all on any processor, except if you are running Apache modules which aren’t thread-safe. mod_php is the most common one, but you don’t need to use that as there is mod_fcgid and running PHP under fcgi.
@Walter
A bit late however it might help someone else. I came across this as I was looking into a similar issue. The easiest way is per a forum entry at http://nixcraft.com/getting-started-tutorials/876-display-number-processors-linux.html:
grep -c processor /proc/cpuinfo
This returns the exact number of available cores, virtual or not.
One way to find out how many physical socketed CPUs there are is to eliminate any extra cores:
grep core\ id /proc/cpuinfo | grep -c \ 0$
Unfortunately if multiple physical CPUs only have 1 core each this returns zero. The following (clumsy) group of commands will return the number of physical CPUs regardless of if there is only a single core per CPU:
grep core\ id /proc/cpuinfo | grep -c \ 0$ | grep ^0$ >> /dev/null && grep -c processor /proc/cpuinfo || grep core\ id /proc/cpuinfo | grep -c \ 0$
Hi Tricky, thanks for the info! My output for these commands is 1, than 0, than 1 again. So I’m guessing my VPS uses 1 single core CPU?
That is correct – however the clumsy command should be run as one very long command all at once and you should only get 1 output result.
Bear in mind that this long command is more informational than useful as it returns the number of processors – however an application should much rather want to know the number of cores.
VPSs rarely get more than one core. If you have a quad-core physical server shared by 16 VPSs it makes no sense to have more than one virtual core assigned to each VPS.
However if you have a single VPS on a quad-core physical server (there are some scenarios where this is a good idea) then it makes sense to have all 4 cores assigned to the single VPS.
Great.. its works for me.. thanks a lot
hi , i am accessing a solaris server from putty. i dont find any cpuinfo file in proc directory, actually proc directory is for storing all fds. How can we find this file there? r tell me how to find CPU information in solaris.
Hello, friends
In the terminal I typed the command
cat /proc/cpuinfo
and I got that:
processor : 0
vendor_id : AuthenticAMD
cpu family : 16
model : 4
model name : AMD Phenom(tm) II X4 940 Processor
stepping : 2
cpu MHz : 800.000
That is just a part of the hole text, but pay attention that: “cpu MHz: 800”. It is not correct, because my CPU speed is 3 GHz. Why is that?
Thanks in advance.
@kishor – Solaris used to also have /proc/cpuinfo. But now, instead, I believe the command to use is “psrinfo -v”
@Hristiyan – You might be using an application such as cpufreq. When your CPU is idle it can automatically throttle your CPU down to the lowest speed it can go in order to save energy (electricity costs/etc) as well as extend the life of the CPU. When your CPU gets really busy and 800MHz isn’t enough it should automatically increase it, possibly in increments, or maybe even straight back up to 3GHz. Google a bit for info on your distribution and CPU throttling and you will probably find relevant information on how to check this.
I could always be wrong though. 😉
Thank you, Tricky, for the answer. I searched some info about my CPU and I found that you are right – 800 MHz is a power saving mode. That’s why CPU info tool displays such frequency.
I was looking for processor architecture. In Ubuntu I find the following 2 command which was useful. These commands were absent in CentOS, RedHat and Slackware.
# lshw
# lscpu
processor : 3
vendor_id : AuthenticAMD
cpu family : 15
model : 65
model name : Dual-Core AMD Opteron(tm) Processor 2220
stepping : 3
cpu MHz : 2792.802
cache size : 1024 KB
physical id : 1
siblings : 2
core id : 1
cpu cores : 2
fpu : yes
fpu_exception : yes
cpuid level : 1
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt
rdtscp lm 3dnowext 3dnow pni cx16 lahf_lm cmp_legacy svm extapic cr8_legacy
bogomips : 5585.25
TLB size : 1088 4K pages
clflush size : 64
cache_alignment : 64
address sizes : 40 bits physical, 48 bits virtual
power management: ts fid vid ttp tm stc
what does cpu cores and siblings mean .
The siblings property is a way for you to see whether or not HyperThreading is in use.
siblings=2 means that 1 physical core is showing in cpuinfo as if it were 2 cores.
Hi there , under Ubuntu Maverick 10.10 i used this line to get CPU Speed Info :
dmesg | grep “MHz processor” | cut -d ” ” -f07 | sed ‘s/[.].*//’
But under Ubuntu Natty 11.04 , this dont work , and only show “evbug”
and the “cat /proc/cpuinfo” its not util for me.
HI,
I want to check the load of the CPU’s individually in linux,can any one help me on this..Thanks in advance
Nag: In Fedora 13 you can see the CPU load graphically in real time: System > About This Computer > Resouces > CPU History.
I’m not sure how you all the get the output for the number of processes but when I do in my server, I see it in seven entries having processor values like below. In this case can I consider I have 7 processors ? So even if top load avg shows ‘5’, I don’t have to worry…??
]$ grep processor /proc/cpuinfo
processor : 0
processor : 1
processor : 2
processor : 3
processor : 4
processor : 5
processor : 6
processor : 7
Since it is counting from zero, your output is showing 8 entries.
In theory having a load of 5 can be okay. Its probably better to measure other aspects of the server’s performance against what you really need, such as responsiveness.
For example if a mail filtering server is slow and this causes a 1-2 minute delay in mail delivery, very few (if any) end-users are going to notice. All you might care about in that instance is how much mail per minute the server can handle and whether or not the server’s spools ever go out of control. The small backlog (thus causing the delay) isn’t good but it is not a mission-critical problem and the end-users are still happy.
On the other hand, if a web server is slow end-users WILL notice, and they definitely won’t be happy. 🙂
Load average is only a pretty rough indication of your load. It’s the queue depth, really.
Hypothetically, close to 1 is ideal – it means your server is cruising along. As to what is too high, that doesn’t just depend on the number of processor cores but also on what exactly you’re doing. A load average of 11 might not faze a particular workload. If your workload is entirely comprised of stuff that does not need to be done immediately – that is, it’s just background processing, then it really doesn’t matter how high this gets.
Think of it like people waiting in line at the airport, if there are four people serving and four people waiting it’s *okay*. If there are four people serving but usually only around one person waiting it’s ideal. If there are four people serving but 31 people waiting then obviously there’s going to be quite a delay. But you’re not taking into account how quickly each of those 31 people will be served. Hope this analogy helps.
The explanation on load avg is quite perfect, but I have read somewhere if the load avg is 2 and it has 2 processor then its fine. If its a single processor then the ideal load avg should be lesser than 1. Not sure if this is how we should assume things against number of processor with load avg. vmstat and iostat shows idle time as 68%. But I don’t see any issues with end user, whereas my top proc is mysql demon for DB, pls see below. It has 5 as load avg and my total no: of procs are 8 so in this case I don’t have to worry according to my above approach, do let me know if I need to worry in the real world.
Thanks!!
top – 09:46:06 up 96 days, 13:25, 13 users, load average: 5.05, 4.82, 4.79
Tasks: 410 total, 1 running, 403 sleeping, 0 stopped, 6 zombie
Cpu(s): 39.5%us, 15.0%sy, 0.0%ni, 43.9%id, 0.8%wa, 0.1%hi, 0.7%si, 0.0%st
Mem: 16624824k total, 16273580k used, 351244k free, 249740k buffers
Swap: 32772332k total, 88k used, 32772244k free, 11028372k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
3125 mysql 25 0 601m 463m 5268 S 385.5 2.9 41175:58 mysqld
31572 tpos 25 0 1273m 203m 7260 S 16.6 1.3 8:05.54 java
I typed the command known:
grep -c processor /proc/cpuinfo
and the result is 4. This number means 4 threads or 2 cores ?
After that I try command:
grep CPU /proc/cpuinfo
and the result is:
model name : Intel(R) Xeon(R) CPU 5140 @ 2.33GHz
model name : Intel(R) Xeon(R) CPU 5140 @ 2.33GHz
model name : Intel(R) Xeon(R) CPU 5140 @ 2.33GHz
model name : Intel(R) Xeon(R) CPU 5140 @ 2.33GHz
But if I install and configure nginx from the Debian repository, the OS download the amd64 package? Why? And working properly. Any explanation?
thanks for the info, just what I needed. Who needs man pages eh? (or a memory for that matter!) 🙂
Источник