top Command in Linux: Monitor Processes in Real Time

By 

Published on

5 min read

Using the Linux top command to monitor processes and resource usage

top is a command-line utility that displays running processes and system resource usage in real time. It helps you inspect CPU usage, memory consumption, load averages, and process activity from a single interactive view.

This guide explains how to use top to monitor your system and quickly identify resource-heavy processes.

top Command Syntax

The syntax for the top command is as follows:

txt
top [OPTIONS]

Run top without arguments to open the interactive monitor:

Terminal
top

Understanding the top Output

The screen is split into two areas:

  • Summary area — system-wide metrics displayed in the header lines
  • Task area — per-process metrics listed below the header

A typical top header looks like this:

output
top - 14:32:01 up 3 days,  4:12,  2 users,  load average: 0.45, 0.31, 0.28
Tasks: 213 total,   1 running, 212 sleeping,   0 stopped,   0 zombie
%Cpu(s):  3.2 us,  1.1 sy,  0.0 ni, 95.3 id,  0.2 wa,  0.0 hi,  0.1 si,  0.0 st
MiB Mem :  15886.7 total,   8231.4 free,   4912.5 used,   2742.8 buff/cache
MiB Swap:   2048.0 total,   2048.0 free,      0.0 used.  10374.2 avail Mem

    PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND
   1234 www-data  20   0  123456  45678   9012 S   4.3   0.3   0:42.31 nginx
    987 mysql     20   0  987654 321098  12345 S   1.7   2.0   3:12.04 mysqld
   5678 root      20   0   65432   5678   3456 S   0.0   0.0   0:00.12 sshd

CPU State Percentages

The %Cpu(s) line breaks CPU time into the following states:

  • us — time running user-space (non-kernel) processes
  • sy — time running kernel processes
  • ni — time running user processes with a manually adjusted nice value
  • id — idle time
  • wa — time waiting for I/O to complete
  • hi — time handling hardware interrupt requests
  • si — time handling software interrupt requests
  • st — time stolen from this virtual machine by the hypervisor (relevant on VMs)

High wa typically points to a disk or network I/O bottleneck. High us or sy points to CPU pressure. For memory details, see the free command. For load average context, see uptime .

Task Area Columns

ColumnDescription
PIDProcess ID
USEROwner of the process
PRScheduling priority assigned by the kernel
NINice value (-20 = highest priority, 19 = lowest)
VIRTTotal virtual memory the process has mapped
RESResident set size — physical RAM currently in use
SHRShared memory with other processes
SProcess state: R running, S sleeping, D uninterruptible, Z zombie
%CPUCPU usage since the last refresh
%MEMPercentage of physical RAM in use
TIME+Total CPU time consumed since the process started
COMMANDProcess name or full command line (toggle with c)

Common Interactive Controls

Press these keys while top is running:

KeyAction
qQuit top
hShow help
kKill a process by PID
rRenice a process
PSort by CPU usage
MSort by memory usage
NSort by PID
TSort by running time
1Toggle per-CPU core display
cToggle full command line
uFilter by user

Refresh Interval and Batch Mode

To change the refresh interval (seconds), use -d:

Terminal
top -d 2

To run top in batch mode (non-interactive), use -b. This is useful for scripts and logs:

Terminal
top -b -n 1

To capture multiple snapshots:

Terminal
top -b -n 5 -d 1 > top-snapshot.txt

Filtering and Sorting

Start top with a user filter:

Terminal
top -u root

To monitor a specific process by PID, use -p:

Terminal
top -p 1234

Pass a comma-separated list to monitor multiple PIDs at once:

Terminal
top -p 1234,5678

To show individual threads instead of processes, use -H:

Terminal
top -H

Thread view is useful when profiling multi-threaded applications — each thread appears as a separate row with its own CPU and memory usage.

Inside top, use:

  • P to sort by CPU
  • M to sort by memory
  • u to show a specific user

For deeper process filtering, combine top with ps , pgrep , and kill .

Quick Reference

CommandDescription
topStart interactive process monitor
top -d 2Refresh every 2 seconds
top -u userShow only a specific user’s processes
top -p PIDMonitor a specific process by PID
top -HShow individual threads
top -b -n 1Single non-interactive snapshot
top -b -n 5 -d 1Collect 5 snapshots at 1-second intervals

Troubleshooting

top is not installed Install the procps package (procps-ng on some distributions), then run top again.

Display refresh is too fast or too slow Use -d to tune the refresh rate, for example top -d 2.

Cannot kill or renice a process You may not own the process. Use sudo or run as a user with sufficient privileges.

FAQ

What is the difference between top and htop? top is available by default on most Linux systems and is lightweight. htop provides a richer interactive UI with color coding, mouse support, and easier navigation, but requires a separate installation.

What does load average mean? Load average shows the average number of runnable or uninterruptible tasks over the last 1, 5, and 15 minutes. A value above the number of CPU cores indicates the system is under pressure. See uptime for more detail.

What is a zombie process? A zombie process has finished execution but its entry remains in the process table because the parent process has not yet read its exit status. A small number of zombie processes is harmless; a growing count may indicate a bug in the parent application.

What do VIRT, RES, and SHR mean? VIRT is the total virtual address space the process has reserved. RES is the actual physical RAM currently in use. SHR is the portion of RES that is shared with other processes (for example, shared libraries). RES minus SHR gives the memory used exclusively by that process.

Can I save top output to a file? Yes. Use batch mode, for example: top -b -n 1 > top.txt.

Conclusion

The top command is one of the fastest ways to inspect process activity and system load in real time. Learn the interactive keys and sort options to diagnose performance issues quickly.

If you have any questions, feel free to leave a comment below.

Linuxize Weekly Newsletter

A quick weekly roundup of new tutorials, news, and tips.

About the authors

Dejan Panovski

Dejan Panovski

Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 800+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.

View author page