🎁 New User? Get 20% off your first purchase with code NEWUSER20 Register Now →
Menu

Categories

top Command

Beginner Process Management man(1)

Display real-time system resource usage and processes

👁 9 views 📅 Updated: Mar 15, 2026
SYNTAX
top [OPTION]...

What Does top Do?

top provides a real-time, dynamic view of running processes sorted by CPU usage. It is the standard tool for monitoring system resource consumption including CPU, memory, swap, and load averages.

top updates its display at regular intervals (default 3 seconds), showing process ID, user, CPU percentage, memory percentage, and command for each process. The header area shows system-wide statistics including uptime, load averages, CPU states, and memory usage.

top supports interactive commands for sorting, filtering, killing processes, and changing display options. It is the go-to tool for identifying what is consuming system resources.

Options & Flags

OptionDescriptionExample
-d Set update interval in seconds top -d 1
-p Monitor specific PIDs only top -p 1234,5678
-u Show only processes for a user top -u www-data
-b Batch mode (for scripting/logging) top -bn 1 > top_output.txt
-n Number of iterations before exit top -bn 5
-H Show individual threads top -H
-i Hide idle processes top -i
-o Sort by field top -o %MEM
-c Show full command line top -c

Practical Examples

#1 Standard monitoring

Opens real-time process monitor. Press q to quit.
$ top

#2 Fast refresh

Updates every 1 second for real-time monitoring during incidents.
$ top -d 1

#3 Monitor specific user

Shows only processes owned by the www-data user.
$ top -u www-data

#4 Single snapshot for logging

Batch mode captures one snapshot — useful for logging and scripts.
$ top -bn 1 | head -20

#5 Monitor specific PIDs

Monitors only the specified process IDs.
$ top -p 1234,5678

#6 Sort by memory

Starts top sorted by memory usage instead of CPU.
$ top -o %MEM

Tips & Best Practices

Interactive shortcuts: While in top: M=sort by memory, P=sort by CPU, k=kill process, r=renice, c=toggle full command, 1=show per-CPU, q=quit.
Load average explained: Load average shows 1/5/15 minute averages of processes wanting CPU. On a 4-core system, load 4.0 means 100% utilization. Above core count indicates overload.
%CPU can exceed 100%: On multi-core systems, a process can show >100% CPU — it means it is using multiple cores. 200% = 2 full cores.

Frequently Asked Questions

How do I sort by memory usage?
Press M while in top, or start with top -o %MEM. Press P to switch back to CPU sorting.
How do I kill a process from top?
Press k, enter the PID, then enter the signal (15 for graceful, 9 for force kill).
What is the difference between top and htop?
htop has a better UI with colors, mouse support, horizontal/vertical scrolling, tree view, and easier process management. htop is top with a better interface.

Master Linux with Professional eBooks

Curated IT eBooks covering Linux, DevOps, Cloud, and more

Browse Books →