Example 1
Basic top Usage
$ top
top - 10:45:23 up 5 days, 3:21, 2 users, load average: 0.52, 0.48, 0.41
Tasks: 189 total, 1 running, 188 sleeping, 0 stopped, 0 zombie
%Cpu(s): 3.2 us, 1.1 sy, 0.0 ni, 95.5 id, 0.1 wa, 0.0 hi, 0.1 si, 0.0 st
MiB Mem : 15924.5 total, 2845.3 free, 8234.2 used, 4845.0 buff/cache
MiB Swap: 2048.0 total, 2048.0 free, 0.0 used. 6823.4 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1234 www-data 20 0 512344 89234 12456 S 5.2 0.5 3:45.67 nginx
5678 mysql 20 0 1234567 234567 45678 S 3.8 1.5 12:34.89 mysqld
9012 user 20 0 345678 67890 23456 S 1.9 0.4 1:23.45 python3
Displays real-time system summary and process information. The top section shows system uptime, users, load averages, task statistics, CPU usage, and memory usage. The bottom section lists processes sorted by CPU usage (default). Updates every 3 seconds by default. Press 'q' to quit.
Load Average: Three numbers show 1, 5, and 15 minute averages. Values near CPU count are normal
Example 2
Sort by Memory Usage
$ top
# Then press 'M' key while top is running
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
5678 mysql 20 0 1234567 234567 45678 S 3.8 1.5 12:34.89 mysqld
1234 www-data 20 0 512344 89234 12456 S 5.2 0.5 3:45.67 nginx
3456 postgres 20 0 456789 78901 34567 S 2.1 0.5 5:67.89 postgres
9012 user 20 0 345678 67890 23456 S 1.9 0.4 1:23.45 python3
Press 'M' (uppercase) while top is running to sort processes by memory usage (%MEM column) in descending order. Essential for identifying memory-hungry processes and investigating memory leaks. Press 'P' to return to CPU sorting.
Interactive Keys: M (memory), P (CPU), N (PID), T (time), press again to reverse
Example 3
Show Individual CPU Cores
$ top
# Then press '1' key while top is running
top - 10:45:23 up 5 days, 3:21, 2 users, load average: 0.52, 0.48, 0.41
Tasks: 189 total, 1 running, 188 sleeping, 0 stopped, 0 zombie
%Cpu0 : 5.2 us, 2.1 sy, 0.0 ni, 92.5 id, 0.2 wa, 0.0 hi, 0.0 si, 0.0 st
%Cpu1 : 2.8 us, 1.3 sy, 0.0 ni, 95.8 id, 0.1 wa, 0.0 hi, 0.0 si, 0.0 st
%Cpu2 : 8.4 us, 3.2 sy, 0.0 ni, 88.2 id, 0.2 wa, 0.0 hi, 0.0 si, 0.0 st
%Cpu3 : 1.5 us, 0.8 sy, 0.0 ni, 97.6 id, 0.1 wa, 0.0 hi, 0.0 si, 0.0 st
Press '1' (number one) to toggle between combined CPU statistics and individual core statistics. Shows utilization per CPU core, helping identify if workload is distributed evenly or if some cores are overloaded. Very useful on multi-core systems.
CPU States: us=user, sy=system, ni=nice, id=idle, wa=IO wait, hi=hardware IRQ, si=software IRQ
Example 4
Filter Processes by User
$ top -u username
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
9012 username 20 0 345678 67890 23456 S 1.9 0.4 1:23.45 python3
12345 username 20 0 234567 45678 12345 S 0.8 0.3 0:45.67 node
67890 username 20 0 123456 34567 8901 S 0.3 0.2 0:12.34 bash
Filters display to show only processes owned by a specific user using the '-u' option. Essential for monitoring user activity or troubleshooting user-specific issues. You can also press 'u' while top is running and enter the username.
Multi-User Systems: Great for isolating resource usage by specific users
Example 5
Set Custom Refresh Interval
$ top -d 1
# Screen updates every 1 second instead of default 3 seconds
Changes the refresh rate using the '-d' option followed by the delay in seconds. Default is 3 seconds. Lower values (like 1 or 0.5) provide more frequent updates for fast-changing situations. Higher values reduce system load. You can also press 'd' while running and enter new delay.
Performance: Faster refresh rates increase CPU overhead of top itself
Example 6
Batch Mode - Save to File
$ top -b -n 1 > top-output.txt
# Runs once in batch mode and saves to file
$ cat top-output.txt
top - 10:45:23 up 5 days, 3:21, 2 users, load average: 0.52, 0.48, 0.41
Tasks: 189 total, 1 running, 188 sleeping...
[Complete top output saved]
Runs top in batch mode with '-b' (non-interactive) and '-n' to specify number of iterations. Perfect for logging, scripts, or automated monitoring. Combine with cron for periodic snapshots of system state. Output can be parsed by other tools.
Automation: Use in cron jobs for historical performance data collection
Example 7
Show Full Command Line
$ top -c
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1234 www-data 20 0 512344 89234 12456 S 5.2 0.5 3:45.67 nginx: worker process
5678 mysql 20 0 1234567 234567 45678 S 3.8 1.5 12:34.89 /usr/sbin/mysqld --daemonize
9012 user 20 0 345678 67890 23456 S 1.9 0.4 1:23.45 python3 /home/user/app.py
Displays full command lines instead of just process names using the '-c' option. Shows complete arguments and paths, making it much easier to identify exactly which script or application is running. Toggle on/off by pressing 'c' while top is running.
Debugging: Essential when multiple instances of same program run with different arguments
Example 8
Kill Process from Within top
$ top
# Press 'k', enter PID when prompted, then enter signal (default 15)
PID to signal/kill [default pid = 1234]: 5678
Send pid 5678 signal [15/sigterm]: 9
# Process 5678 killed with signal 9 (SIGKILL)
Kill processes directly from top by pressing 'k', entering the PID, and choosing a signal. Default signal is 15 (SIGTERM) for graceful shutdown. Use signal 9 (SIGKILL) for forced termination. Convenient for quick process management without leaving top.
Common Signals: 15=SIGTERM (graceful), 9=SIGKILL (force), 1=SIGHUP (reload config)
Example 9
Change Process Priority (Renice)
$ top
# Press 'r', enter PID, then enter new nice value (-20 to 19)
PID to renice [default pid = 1234]: 5678
Renice PID 5678 to value: 10
# Process 5678 priority changed (higher nice = lower priority)
Change process priority by pressing 'r', entering the PID, and setting a new nice value. Nice values range from -20 (highest priority) to 19 (lowest priority). Only root can decrease nice values (increase priority). Useful for managing resource allocation.
Remember: Higher nice value = lower priority (be "nicer" to other processes)
Example 10
Show Only Specific Process
$ top -p 1234,5678,9012
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1234 www-data 20 0 512344 89234 12456 S 5.2 0.5 3:45.67 nginx
5678 mysql 20 0 1234567 234567 45678 S 3.8 1.5 12:34.89 mysqld
9012 user 20 0 345678 67890 23456 S 1.9 0.4 1:23.45 python3
Monitors specific processes by PID using the '-p' option. Provide comma-separated list of PIDs. Perfect for focusing on particular applications or services without distraction from other processes. Great for debugging specific issues.
Focused Monitoring: Ideal for watching critical services or troubleshooting specific problems
Bonus
Interactive Commands Quick Reference
Display Controls:
1 Toggle individual CPU stats
t Toggle CPU summary display
m Toggle memory summary display
c Toggle command line/program name
V Forest view (process hierarchy)
Sorting:
P Sort by CPU usage (default)
M Sort by memory usage
N Sort by PID
T Sort by running time
R Reverse sort order
Filtering:
u Filter by user (prompts for username)
n or # Set number of processes to display
o/O Add filter expressions
Process Management:
k Kill a process (prompts for PID and signal)
r Renice a process (change priority)
Display Options:
d Change refresh delay
W Write current settings to ~/.toprc
H Toggle threads display
i Toggle idle processes
z Toggle color
Navigation:
Space Force refresh
h or ? Help screen
q Quit
Field Management:
f Choose which fields to display
F or O Choose sort field
Complete reference of interactive commands available while top is running. Master these to efficiently monitor and manage system resources in real-time.
Reference
Common top Command Options Quick Reference
Basic Usage:
top Start top with default settings
top -h Display help and exit
top -v Display version and exit
User and Process Filtering:
top -u username Show only user's processes
top -U username Show processes of user (by UID)
top -p PID Monitor specific PID(s)
top -p 1234,5678 Monitor multiple PIDs
Display Options:
top -c Show full command line
top -d seconds Set refresh delay (default 3.0)
top -n number Number of iterations then exit
top -b Batch mode (non-interactive)
top -H Show individual threads
top -i Don't show idle processes
Output Control:
top -b -n 1 Single snapshot
top -b -n 1 > file Save snapshot to file
top -b -d 5 -n 12 Monitor for 1 minute (5sec x 12)
Useful Combinations:
top -u apache -c Apache processes with full commands
top -b -n 1 | head -20 Quick system snapshot
top -d 1 -p $(pgrep nginx | paste -sd,) Monitor all nginx PIDs
watch -n 1 'top -b -n 1 | head -20' Alternative monitoring
Comprehensive reference for top command usage including options for filtering, display control, and common combinations for system monitoring and troubleshooting.