Linux CPU Usage Monitoring: Find High CPU Processes Fast

Quick Linux Tip #103:

Question: Something is pegging my CPU. How do I pinpoint it with real-time refresh?

Try: top -b -n 1 -o %CPU | head -20

Info: Running top in batch mode (-b -n 1) executes a single non-interactive snapshot, while -o %CPU dynamically sorts processes by CPU utilization for quick diagnostics and scripting.

Examples:

  • $ top -b -n 1 -o %MEM | head  # Snapshot sorted by memory consumption
  • $ top -b -n 1 -u mysql  # Filter snapshot processes by specific user
  • $ top -b -n 1 -p 3456,2134  # Inspect specific target Process IDs (PIDs)

Note: Pay attention to wa (I/O wait; high values indicate disk bottlenecks) and st (stolen CPU; high values indicate hypervisor contention). Multi-threaded processes can exceed 100% CPU.




LinuxTeck.com
linuxteck:~$ top -b -n 1 -o %CPU | head -20
top - 09:34:12 up 23 days,  4:12,  2 users,  load average: 2.45, 1.89, 1.67
Tasks: 234 total,   3 running, 231 sleeping,   0 stopped,   0 zombie
%Cpu(s): 45.2 us,  8.3 sy,  0.0 ni, 44.5 id,  1.5 wa,  0.0 hi,  0.5 si,  0.0 st
MiB Mem : 15987.4 total,  2345.6 free,  8901.2 used,  4740.6 buff/cache
MiB Swap:  2048.0 total,  2048.0 free,     0.0 used. 6543.2 avail Mem

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND
 3456 mysql     20   0 4823456 2345m  12456 S  87.3  14.7 234:12.34 mysqld
 2134 www-data  20   0  456872   87m  23456 R  45.2   0.5  89:23.45 nginx
 5678 linuxteck 20   0 1876543  876m  34567 S  12.3   5.4 123:45.67 chrome
 4321 root      20   0  234567   34m   4567 S   3.4   0.2   5:12.34 systemd-journald
 1234 nginx     20   0  567890   45m   6789 R   2.1   0.3   8:56.78 nginx
linuxteck:~$

PREVIOUS ARTICLE Quick Linux Tip #102: Linux DNS Troubleshooting: Trace DNS Resolution in 3 Steps NEXT ARTICLE Quick Linux Tip #104: Linux Free Space Wiping: 4 Steps to Overwrite Deleted Data
About John Britto

John Britto Founder & Chief-Editor @LinuxTeck. A Computer Geek and Linux Intellectual having more than 20+ years of experience in Linux and Open Source technologies.

View all posts by John Britto →

Leave a Reply

Your email address will not be published.