Linux Display CPU Information Number of CPUs and Their Speed

by on July 29, 2006 · 30 comments· LAST UPDATED May 30, 2013

in , ,

How do I display CPU information like number of CPUs, threads, cores, sockets, NUMA nodes, information about CPU caches, CPU family, model and stepping and their speed on Linux operating systems?

You need to use Proc (/proc) file system provides information about CPU and their speed which is a pseudo-filesystem. It is used as an interface to kernel data structures. It is commonly mounted at /proc. Most of it is read-only, but some files allow kernel variables to be changed.

Tutorial details
DifficultyIntermediate (rss)
Root privilegesNo
Requirements/proc, ls, and lscpu
Estimated completion timeN/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:

processor       : 0
vendor_id       : GenuineIntel
cpu family      : 15
model           : 4
model name      : Intel(R) Xeon(TM) CPU 3.00GHz
stepping        : 3
cpu MHz         : 2992.991
cache size      : 2048 KB
physical id     : 0
siblings        : 2
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 ht tm pbe nx lm pni monitor ds_cpl cid
bogomips        : 5931.00
processor       : 1
vendor_id       : GenuineIntel
cpu family      : 15
model           : 4
model name      : Intel(R) Xeon(TM) CPU 3.00GHz
stepping        : 3
cpu MHz         : 2992.991
cache size      : 2048 KB
physical id     : 0
siblings        : 2
.....
...
....

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:

Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
CPU(s):                8
Thread(s) per core:    2
Core(s) per socket:    4
CPU socket(s):         1
NUMA node(s):          1
Vendor ID:             GenuineIntel
CPU family:            6
Model:                 30
Stepping:              5
CPU MHz:               1199.000
Virtualization:        VT-x
L1d cache:             32K
L1i cache:             32K
L2 cache:              256K
L3 cache:              8192K

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:
TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 30 comments… read them below or add one }

1 wessy May 27, 2009 at 9:25 am

thanks, works

Reply

2 user July 1, 2009 at 6:19 am

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???!!

Reply

3 Blake Acheson July 31, 2009 at 5:34 pm

you have 16 virtual processors total…that is correct

2 quads but each of the these physical processors implement hyperthreading

2 x (4×2)=16

Reply

4 user1 September 7, 2013 at 9:49 am

It makes you wonder why he/she even needs two Xeons

Reply

5 Dave February 10, 2010 at 2:36 pm

Many thanks!

Reply

6 thomasrutter May 5, 2010 at 8:12 am

For just the number of CPUs and speed, this may be simpler.

cat /proc/cpuinfo | grep MHz

Reply

7 Walter Vos May 26, 2010 at 7:29 am

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?

Reply

8 mmj September 21, 2010 at 3:01 am

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.

Reply

9 Tricky September 20, 2010 at 4:49 pm

@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$

Reply

10 Walter Vos September 20, 2010 at 5:41 pm

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?

Reply

11 Tricky September 21, 2010 at 4:28 pm

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.

Reply

12 arun January 23, 2012 at 9:16 am

Great.. its works for me.. thanks a lot

Reply

13 kishor December 12, 2010 at 9:48 pm

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.

Reply

14 Hristiyan March 5, 2011 at 4:35 am

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.

Reply

15 Tricky March 7, 2011 at 12:09 am

@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. ;)

Reply

16 Hristiyan March 9, 2011 at 4:11 am

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.

Reply

17 Russell April 27, 2011 at 6:17 am

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

Reply

18 Mallik May 18, 2011 at 1:13 pm

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 .

Reply

19 Tricky May 18, 2011 at 7:05 pm

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.

See http://www.redhat.com/archives/nahant-list/2006-January/msg00176.html

Reply

20 Inukaze October 20, 2011 at 12:26 am

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.

Reply

21 Nag January 31, 2012 at 10:16 am

HI,
I want to check the load of the CPU’s individually in linux,can any one help me on this..Thanks in advance

Reply

22 Jack February 2, 2012 at 5:14 am

Nag: In Fedora 13 you can see the CPU load graphically in real time: System > About This Computer > Resouces > CPU History.

Reply

23 Mannoj March 6, 2012 at 12:34 pm

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…??

[pprod@ssbank ~]$ grep processor /proc/cpuinfo
processor : 0
processor : 1
processor : 2
processor : 3
processor : 4
processor : 5
processor : 6
processor : 7

Reply

24 Tricky March 7, 2012 at 12:34 am

Since it is counting from zero, your output is showing 8 entries.

Reply

25 Tricky March 7, 2012 at 12:44 am

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. :)

Reply

26 mmj March 7, 2012 at 1:02 am

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.

Reply

27 Mannoj March 7, 2012 at 4:37 am

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

Reply

28 electro June 4, 2012 at 7:11 pm

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?

Reply

29 Jules June 18, 2012 at 11:42 pm

thanks for the info, just what I needed. Who needs man pages eh? (or a memory for that matter!) :)

Reply

30 clark November 15, 2012 at 8:40 am

you can use

watch “cat /proc/cpuinfo | grep MHz”

to view ur cpu speed, it’ll refresh every 2.0 secs

Reply

Leave a Comment

Tagged as: , , , , , , , , , ,

Previous Faq:

Next Faq: