ATB Team

How to Check the Number of CPUs in Linux

If you’re working with a Linux system, whether it’s for development, system administration, or just curiosity, knowing how many CPUs your system has can be essential. Fortunately, Linux provides several ways to check this information. In this post, we’ll go through some simple commands you can use to determine the number of CPUs (or cores) in your machine.

1. Using the lscpu Command

The lscpu command is one of the easiest ways to get detailed information about the CPUs on your system. It provides a summary of the architecture, including the number of CPUs, cores, threads, and more.

To use it, just open a terminal and type:

lscpu

You’ll get output like this:

Architecture:        x86_64
CPU(s): 4
On-line CPU(s) list: 0-3
Thread(s) per core: 2
Core(s) per socket: 2
Socket(s): 1
NUMA node(s): 1
...

In this example:

  • CPU(s): 4 tells you that the system has 4 CPUs (or threads).
  • Core(s) per socket: 2 indicates that there are 2 cores per CPU socket.
  • Thread(s) per core: 2 shows the number of threads running per core (useful if you have hyper-threading enabled).

2. Checking /proc/cpuinfo

Another way to check CPU information is by looking at the /proc/cpuinfo file. This file contains detailed information about each individual processor on your system.

To view it, run:

cat /proc/cpuinfo

You’ll see detailed information for each processor. For example:

processor   : 0
vendor_id : GenuineIntel
cpu family : 6
model : 158
model name : Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
...
processor : 1
vendor_id : GenuineIntel
cpu family : 6
model : 158
model name : Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
...

If you just want to count the number of processors listed, you can use the grep command:

grep -c processor /proc/cpuinfo

This will give you the number of logical processors on your system (including threads).

3. Using top or htop

If you prefer an interactive view, both top and htop (a more user-friendly version of top) can display the number of CPUs and other system resources.

  • For top: Just run the command top in your terminal, and look for the CPU stats in the top section.
  • For htop: If you have htop installed, it shows an easy-to-read graphical display of your CPUs at the top of the terminal window. You can install it with:sudo apt install htop # For Debian/Ubuntu-based systems sudo yum install htop # For CentOS/RedHat-based systems

Run htop, and you’ll see a nice visual breakdown of your CPU usage, including a graph for each individual CPU/core.

4. Using nproc

If you’re looking for a super quick way to find out the number of processing units (i.e., CPUs or cores), you can use the nproc command:

nproc

This command will simply return the number of processing units available on your system.

Leave a Comment