Introduction / Why This Matters
The top command is a fundamental, always-available tool for quick, real-time system monitoring in Linux. Unlike graphical task managers, top runs directly in the terminal and shows which processes consume the most resources (CPU, memory), overall system load, and system uptime. Mastering top is critical for system administrators, developers, and anyone who works with servers or wants to understand why their computer has become slow.
After completing this guide, you will be able to:
- Read and understand
top's output. - Find resource-hogging processes.
- Filter and sort processes by specific criteria.
- Manage processes (change priority, terminate) directly from the interface.
- Customize the display for your specific tasks.
Requirements / Preparation
- Access to a Linux terminal (locally or via SSH).
- The
topcommand is preinstalled on almost all distributions as part of theprocps-ngorprocpspackage. If it's missing (unlikely), install it:- Debian/Ubuntu:
sudo apt update && sudo apt install procps - RHEL/CentOS/Fedora:
sudo yum install procps-ngorsudo dnf install procps-ng
- Debian/Ubuntu:
- Permissions: To view all processes (including system ones), you typically need root privileges (
sudo top). Managing processes not owned by your user also requires elevated privileges. - Basic understanding of what a process is (PID), CPU usage, and memory (RAM/Swap).
Step-by-Step Guide
Step 1: Run top and Understand the Interface
Type top in the terminal and press Enter.
top
You will see a screen divided into two main areas:
- Upper part (Summary Area) — system summary:
top— line with version, system uptime (up), number of users (users), and load average (1, 5, 15 min).Tasks:— total number of processes and their states (running, sleeping, stopped, zombie).%Cpu(s):— CPU utilization:us(user),sy(system),ni(nice),id(idle),wa(wait/I/O),hi(hardware IRQ),si(software IRQ),st(steal time — for virtualization).KiB Mem:andKiB Swap:— RAM and swap file/partition usage (total, used, free, buff/cache).
- Lower part (Processes Area) — list of processes (sorted by
%CPUby default). Key columns:PID— process identifier.USER— process owner.%CPU— CPU share used by this process.%MEM— share of physical memory used.TIME+— total CPU time used since the process started.COMMAND— command/process name.
💡 Tip: Press
hor?at any time to see help for all interactive commands.
Step 2: Master Basic Control and Sorting
top is an interactive program. Control is done with single key presses.
- Sorting (most common operation):
P— sort by%CPU(default).M— sort by%MEM.N— sort byPID(ascending).T— sort byTIME+(CPU time).
- Filtering (show only what you need):
- Press
O(capital O). A field for entering a condition will appear. - To show only processes for user
nginx, enter:USER=nginxand press Enter. - To show processes where
%CPUexceeds 5.0, enter:%CPU>5.0. - To reset the filter, press
O, enter=, and press Enter.
- Press
- Changing displayed fields:
- Press
f. You will enter the field selection menu. - Use up/down arrows to navigate the list.
- Space — select/deselect a field (marked with
*will be shown). - To the right of selected fields, you can change their order (arrows
<-and->). - Done? Press
Enter, thenqto exit the menu.
- Press
Step 3: Manage Processes Directly from top
This is one of the most powerful features.
- Terminate (kill) a process:
- Note the
PIDof the target process (or find it via filter). - Press
k. - Enter the
PIDand press Enter. - Enter the signal number (default
15—SIGTERM, graceful termination). For forceful termination, use9(SIGKILL). Press Enter.
⚠️ Important: Signal
9(SIGKILL) does not allow the process to shut down gracefully and save data. Use only ifSIGTERMfails. - Note the
- Change a process's priority (nice):
- Press
r. - Enter the process
PID. - Enter the new
nicevalue (from-20— highest priority, to19— lowest). Usually, you increase nice (lower priority) for background tasks to avoid interfering with interactive ones. - Press Enter.
- Press
Step 4: Customize the Interface and Use Useful Hotkeys
z— toggle color highlighting (very helpful for visually distinguishing active processes).x— highlight the column used for sorting (highlighted by default).b— toggle bold text/color for active (CPU-using) processes.u— quickly filter processes by username (enter name or leave empty for all).V— switch to process tree view (forest view) to see hierarchy (parent/child processes). Very useful for understanding which daemon spawned which process.c— toggle command display: full path and arguments (/usr/bin/python3 script.py) or just the command name (python3).Space— immediately refresh the screen (if paused).s— change the screen refresh delay (in seconds, default 3.0). Enter a smaller value for more frequent updates.q— exittop.
Verification Checklist
You have successfully mastered top if you can:
- Within 10 seconds, find the process with the highest
%CPUand%MEMwithout using a mouse. - Filter the list to show only processes for user
postgres(or any other user). - See the tree of child processes for
systemdorsshd. - Correctly terminate a test process (e.g., started with
sleep 1000) usingkand signal15. - Save a static snapshot of system state with the command
top -b -n 1 > system_snapshot.txtand confirm the file was created and contains readable text.
Common Issues & Solutions
- I don't see all processes / processes from another user.
- Cause: Insufficient permissions.
- Solution: Run
topwithsudo:sudo top. Be careful when managing root-owned processes.
- Processes with low %CPU are not displayed, even though there are many.
- Cause: By default,
topshows only active processes (with non-zero %CPU or %MEM) or limits the number of rows for the list. A filter might also be active. - Solution: Press
fand ensure fields likeA(VIRT) aren't hiding processes. Reset the filter (O→=). Increase the number of displayed rows (settings may vary by version).
- Cause: By default,
- I can't find a process by name (e.g.,
nginx).- Cause: The
COMMANDcolumn may show only the binary name (nginx), not the full command line. Or the process might be in stateD(uninterruptible sleep, often due to I/O) and not accumulating %CPU. - Solution: Use a filter on
COMMAND(O→COMMAND=nginx). Or presscto switch to full command line display. To find "sleeping" processes, sort byTIME+or use the more flexibleps aux | grep nginx.
- Cause: The
topdoesn't show process network activity.- Cause: Standard
toplacks built-in fields for network statistics (in/out). - Solution: For network monitoring, use separate tools:
nethogs,iftop,ss -tuna, ornetstat -tunap. Sometopversions (e.g., fromprocps-ngon RHEL) may have limited support for network stats fields (n), but this is non-standard.
- Cause: Standard
- I can't exit top; I pressed a random key and the interface is broken.
- Solution: Press
qto exit. If that doesn't work, tryCtrl+C. As a last resort, close the terminal or SSH window.
- Solution: Press
- I want a more visually appealing interface.
- Solution: Install
htop(sudo apt install htoporsudo yum install htop). It's a full-featuredtopreplacement with mouse support, colors, and convenient navigation.
- Solution: Install