• ARTICLES
SEARCH

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.

Lowell Heddings, better known online as the How-To Geek, spends all his free time bringing you fresh geekery on a daily basis. You can follow him on if you'd like.

  • Published 02/22/07

Comments (10)

  1. Rayz

    Hi,
    this will give you the same result and saves you having to type a couple of characters

    grep processor /proc/cpuinfo |wc -l

  2. Nate

    This will save you a pipe
    grep -c processor /proc/cpuinfo

  3. Paul Boddie

    Won’t this count CPUs with hyperthreading twice? My computer has one Pentium 4 (Prescott) CPU, but has two processor entries in cpuinfo.

  4. odor

    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

  5. Ron

    To get the count of physical CPUs, this works by counting the unique physical ids
    grep “physical id” /proc/cpuinfo |sort -u|wc -l

  6. Alex

    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

  7. Tricky

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

  8. Chris

    For physical CPU’s you could also do:

    dmidecode | grep CPU

  9. Nathan B

    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

  10. kynan

    This will give you the physical core count:
    fgrep -m 1 ‘cpu cores’ /proc/cpuinfo | cut -d ‘ ‘ -f 3

Get Free Articles in Your Inbox!

Join 134,000 newsletter readers

Email:

Go check your email!