Subscribe to How-To Geek

Recommended: Click Here to Run a Free Scan for Common PC Errors   [Sponsored Link]

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.

The Geek is the founder of How-To Geek and a geek enthusiast. When he's not coming up with great how-to articles, he's probably writing at his personal blog. This article was written on 02/22/07 and tagged with: Ubuntu, Suse Linux

Comments (5)

  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


Leave a Comment




Leave your friendly comment here. If you have a computer help question, leave it on the forums instead.

Note: Your comment may not show up immediately on the site.

Copyright © 2006-2008 HowToGeek.com. All Rights Reserved.