How-To Geek
Display Number of Processors on Linux
If you’ve just upgraded your Linux box, or you are wondering how many processors a remote server has, there’s a quick and dirty command you can use to display the number of processors.
On Linux, /proc/cpuinfo contains all of the processor information for all current processors in your computer. This will include the speed, the amount of on-chip cache, processor type, and how many cores.
Here’s the command:
cat /proc/cpuinfo | grep processor | wc -l
The command just looks in the /proc/cpuinfo file, pulls out the number of lines containing the word “processor” and passes them into wc (word count), which returns a count of the CPUs in the system.
Here’s what it returned on my remote server:
[root@root]# cat /proc/cpuinfo | grep processor | wc -l
4
Note that if you have a dual-core processor, it will return each core as a separate processor. You can look at the full output of cat /proc/cpuinfo to see if the chips are dual-core.
|
Subscribe |
Daily Email Updates |
|
You can get our how-to articles in your inbox each day for free. Just enter your email below: |
- By The Geek on 02/22/07
Comments (10)
Comments are closed on this post.
If you'd like to continue the discussion on this topic, you can do so at our forum.
Go to the Forum

Hi,
this will give you the same result and saves you having to type a couple of characters
grep processor /proc/cpuinfo |wc -l
This will save you a pipe
grep -c processor /proc/cpuinfo
Won’t this count CPUs with hyperthreading twice? My computer has one Pentium 4 (Prescott) CPU, but has two processor entries in cpuinfo.
Well… Sorry to say that it doesn’t work most of the time. Beside multithreadin processors, It is common that entry on a single processor has multiple occurence of word “processor” (both in the procesor identifier and model name.
On my ancient pemtium M laptop it reports 2 processors because ist modelname is “Intel(R) Pentium(R) M processor 1.73GHz”.
This might help:
grep -c ^processor /proc/cpuinfo
To get the count of physical CPUs, this works by counting the unique physical ids
grep “physical id” /proc/cpuinfo |sort -u|wc -l
This comment I wrote may also help you (it’s actually for Linux): http://www.howtogeek.com/howto/solaris/get-the-processor-type-on-solaris/#comment-64380
@Ron
With a single-core CPU, “physical id” will return zero rows
I’ve ended up with the following admittedly clumsy solution:
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$
For physical CPU’s you could also do:
dmidecode | grep CPU
Had a bit of an exception on my machine – the “grep processor” command found the following 2 lines:
processor : 0
model name : Intel(R) Pentium(R) M processor 1.80GHz
(the command incorrectly returned ’2′ as my number of processors.)
It needs a caret before ‘processor’, so that it only finds it at the beginning of the line: cat /proc/cpuinfo | grep “^processor” | wc -l
This will give you the physical core count:
fgrep -m 1 ‘cpu cores’ /proc/cpuinfo | cut -d ‘ ‘ -f 3