Master Linux Performance Monitoring: A Deep Dive into the top Command
This guide explains how to interpret the Linux top command output, covering load average, CPU and memory usage, zombie processes, swap, and both command‑line and interactive controls to help you monitor and troubleshoot system performance effectively.
Content Introduction
The top command is a common Linux performance analysis tool that displays real‑time resource usage for each process.
Load Average and Basic Information
Top’s first line shows basic system information, including the load average, which represents the average number of runnable or waiting tasks over the past 1, 5, and 15 minutes.
To understand load average, you need to know the number of CPU cores:
系统的核数 = CPU1 x CPU1的核数 + CPU2 x CPU2的核数 + …You can obtain the core count with: grep -c 'model name' /proc/cpuinfo The load‑average saturation value equals the total number of cores; a single‑core system has a saturation of 1, a dual‑core system 2, etc. When the 5‑minute or 15‑minute load average exceeds 0.7 of the saturation value, investigation is required.
0.00 – no load (bridge empty)
0.50 – half of the bridge capacity
1.00 – bridge at full capacity, traffic slows
1.70 – overload, traffic queues heavily
Task Information
Zombie processes are terminated processes that remain in the process table until their parent calls wait(). To clean them, kill the parent process; the init process will adopt and later reap the zombies.
CPU Usage
The top display includes a CPU usage section (see image).
Physical Memory Usage
Memory is divided into buffers (data waiting to be written to disk) and cache (frequently read data kept in RAM). Linux periodically flushes buffers to disk, and you can force this with:
# Write buffers to disk and drop caches
sync && echo 3 > /proc/sys/vm/drop_cachesSwap Usage
Swap is a reserved disk area used when RAM is insufficient. Enabling swap can degrade I/O performance; many cloud providers disable it by default.
Process Details
Top provides a detailed list of processes, including PID, user, CPU%, MEM%, and command (see image).
Flexible Use of top
Command‑line Options
-b: Batch mode; redirect output to a file. -c: Show full command line. -d <seconds>: Set screen refresh interval (e.g., top -d 1 refreshes every second). -s: Secure mode. -S: Cumulative mode. -i: Hide idle and zombie processes. -u <username>: Show processes for a specific user. -p <pid>: Monitor a specific PID. -n <count>: Exit after a given number of iterations.
Interactive Commands
1: Toggle per‑CPU usage. h: Show help screen. k: Kill a process. i: Toggle ignore idle/zombie processes. q: Quit top. r: Renice a process. S: Switch to cumulative mode. s: Change delay between refreshes (seconds or milliseconds). l: Toggle load average and uptime display. m: Toggle memory information. t: Toggle task and CPU state display. c: Toggle command name vs. full command line. M: Sort by resident memory size. P: Sort by CPU usage percentage. T: Sort by time/cumulative time. w: Write current settings to ~/.toprc.
These options and interactive keys allow you to tailor top’s output for detailed performance analysis and troubleshooting.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
ITPUB
Official ITPUB account sharing technical insights, community news, and exciting events.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
