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.
Leave a Reply