top

Real-Time System Monitor

What Does It Do?

The top command provides a real-time, dynamic view of your Linux system, showing live updates of running processes, CPU usage, memory consumption, and system load—refreshing automatically every few seconds.

Think of top like Windows Task Manager, but running in your terminal. It's essential for system administrators because it updates live, letting you watch what's happening right now. You can see which process is suddenly eating all your CPU, monitor memory usage over time, identify runaway processes before they crash your server, track system load averages, and even kill problematic processes directly from the interface. Unlike ps which shows a snapshot, top keeps you informed continuously.

Advertisement

[ Insert Google AdSense Banner Code Here ]

When Should I Use It?

Server Running Slow

Quickly identify which process is hogging resources.

Monitor Performance

Watch CPU and memory usage change in real-time.

Find Memory Leaks

Track processes that keep consuming more memory over time.

Kill Stuck Processes

Press 'k' in top to terminate a problematic process by PID.

Common Commands & Keys

top

Start monitoring system in real-time (default sorted by CPU usage).

top -u username

Show processes only for a specific user (replace "username" with: root, mysql, www-data, postgres, or user).

top -p 1234

Monitor specific process ID (PID 1234).

top -d 5

Set refresh delay to 5 seconds (default is 3 seconds).

Interactive Keys (while top is running):

q Quit top
M Sort by memory usage
P Sort by CPU usage (default)
k Kill a process (prompts for PID)
h Show help
1 Show individual CPU cores
u Filter by username
c Toggle command line/name

Understanding the Display

Load Average (1.23, 1.45, 1.67)

Shows system load over 1, 5, and 15 minutes. On a single CPU, 1.0 = 100% busy. Higher numbers mean processes are waiting.

%CPU

Percentage of CPU time used by each process. Can exceed 100% on multi-core systems.

%MEM

Percentage of physical RAM used by the process.

VIRT / RES / SHR

VIRT = total virtual memory, RES = physical RAM actually used, SHR = shared memory with other processes.

S (Status)

R = Running, S = Sleeping (waiting), D = Uninterruptible sleep, Z = Zombie, T = Stopped.

IMPORTANT TIPS

Exit with 'q': Don't try Ctrl+C to quit top - press q to exit cleanly.

top vs htop: htop is a more user-friendly alternative with colors, mouse support, and easier navigation. Install it with sudo apt install htop.

Don't panic at high CPU: Brief spikes to 100% CPU are normal. Only worry if it stays high constantly or if load average exceeds your CPU count for extended periods.

Try It Yourself

Experience the live top command simulator below. Click "Start top" to begin monitoring, and use the buttons to sort and control the display: