Ubuntu

How many CPU cores do I have Ubuntu 22.04?

How many CPU Cores do I Have Ubuntu 22.04

Multiple CPU (Central Processing Unit) cores enable multitasking and execution of multiple applications simultaneously with the help of Parallel Processing and Multiple Threads. Additionally, multiple-core processors reduce power consumption while enhancing system performance.

System performance can be optimized by knowing the CPU Cores, for example, the allocation of resources during virtual machine creation. Additionally, system administrators can utilize this information while assigning various tasks to servers and while managing servers.

This article will demonstrate different ways of determining the number of CPU Cores on Linux/Ubuntu 22.04 LTS as below:

  • Using nproc Utility.
  • Using lscpu Utility.
  • Using top Utility.
  • Using /proc/cpuinfo File.
  • Using getconf _NPROCESSORS_ONLN.

Method 1: Determining CPU Cores by Using nproc Utility

The “nproc” is a built-in command of Linux that is used to display the number of CPU cores of a system. Here is a practical demonstration of nproc command:

$ nproc

From the below image, it can be seen that there are four CPU cores in our Ubuntu system.

Method 2: Determining CPU Cores by Using lscpu Utility

The “lscpu” utility displays information related to CPU Architecture, threads per core, CPU cores, etc.

$ lscpu

CPU information can be filtered out by using the “egrep” command:

$ lscpu | egrep 'CPU\(s\)'

From the below image, it can be seen that there are four CPU cores in the system.

Method 3: Determining CPU Cores by Using top Utility

“top” is a built-in Linux utility to display real-time system processes.

$ top

Press 1 to view the CPU Core information:

From the above image, it can be seen that there are four CPU cores in the system.

Method 4: Determining CPU Cores by Using /proc/cpuinfo File

The CPU information is stored in /proc/cpuinfo file. This information can be accessed by using the cat command as follows:

$ cat /proc/cpuinfo

Additionally, specific information about the CPU core can be filtered by a combination of “cat”, “grep” and “wc” commands, as demonstrated below:

$ cat /proc/cpuinfo | grep processor | wc -l

From the below image, it can be seen that there are four CPU cores in the system.

Method 5: Determining CPU Cores by Using getconf_NPROCESSORS_ONLN

The number of cores of the system is stored in “getconf_NPROCESSORS_ONLN” in a variable and can be displayed by using the echo statement:

$ echo "Number of CPU/cores available $HOSTNAME is: $(getconf _NPROCESSORS_ONLN)"

From the above image, it can be seen that there are four CPU cores in the system.

Conclusion

In Ubuntu 22.04, CPU core information is displayed by “nproc”, “lscpu”, “top” utility, the “proc/cpuinfo” file output, and by using the “getconf _NPROCESSORS_ONLN” variable. This article has demonstrated different ways of determining the number of CPU Cores on Linux/Ubuntu 22.04 LTS.

Similar Posts