Posted: . At: 11:23 AM. This was 10 months ago. Post ID: 18191
Page permalink. WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters.
These cookies expire two weeks after they are set.


Another good way to get CPU information on Linux and see all cores.


There is a very good selection of utilities on Linux to print CPU information on Linux. I have just found another one. The mpstat utility will print the usage of all CPU cores very easily.

This command runs mpstat, collects data for every processor (-P ALL) at one-second intervals with only one iteration, then uses an AWK script to extract and print average values for each core.

[jcartwright@localhost ~]$ mpstat -P ALL 1 1 | awk '/Average:/ && $2 ~ /[0-9]/ {print "Core", $2 ": ", $3 "%"}'
Core 0:  0.99%
Core 1:  1.00%
Core 2:  4.08%
Core 3:  1.00%
Core 4:  1.98%
Core 5:  0.00%
Core 6:  1.96%
Core 7:  1.00%
Core 8:  2.97%
Core 9:  2.04%
Core 10:  0.00%
Core 11:  2.00%

These are measurements taken at an instant in time, but this is still a good way to get this information.

Install this utility easily.

# For Debian-based systems (Ubuntu) sudo apt-get install sysstat # For RHEL-based systems (CentOS) sudo yum install sysstat # For Arch Linux based systems sudo pacman -S sysstat # For macOS using Homebrew brew install sysstat

This is great and should be a very useful tip.

Here is also a very useful tip to see what process is using the most CPU resources.

While it is not possible to directly associate a process with a specific core in real-time because modern operating systems dynamically allocate processes to different cores, you can list the CPU usage percentage of each running process using the ps command. This information can give you an idea of which processes are consuming more resources at any given time.

Here’s a one-liner that displays the PID (process ID), CPU usage percentage, and command name for each running process.

[jcartwright@localhost ~]$ ps -eo pid,%cpu,comm --sort=-%cpu | head
    PID %CPU COMMAND
   3431 12.3 firefox
   8801  9.5 kworker/u24:0-xfs-blockgc/dm-2
   8335  8.2 kworker/u24:2+events_unbound
   6188  4.8 kworker/u24:1-events_unbound
   3995  4.0 RDD Process
   3628  3.5 WebExtensions
   9512  3.5 Isolated Web Co
   9143  3.2 kworker/u24:4-flush-253:0
   4267  2.6 Isolated Web Co

This a very useful one-liner for Linux.


Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.