Skip to main content

top command

top - display Linux processes

The top command in Linux is a real-time system monitoring tool that displays running processes, CPU, memory, and other system stats. It’s interactive, allowing you to sort, filter, or kill processes directly.

Usage: top [options]

  • options: Flags to customize startup behavior (optional).
  • Runs interactively by default—exit with q.

Common Fields Explained

ColumnDescription
PIDProcess ID
USERProcess owner
%CPUCPU usage percentage
%MEMMemory usage percentage
VIRTVirtual memory used
RESResident (physical) memory used
SState (R=running, S=sleeping, Z=zombie)
TIME+Total CPU time used
COMMANDCommand that started the process

Examples

  • Basic Usage

    Run top to see a live view of system processes.

    top
    • Output (example):

      top - 10:00:00 up 1 day, 2:00,  2 users,  load average: 0.15, 0.20, 0.25
      Tasks: 123 total, 1 running, 122 sleeping, 0 stopped, 0 zombie
      %Cpu(s): 5.0 us, 2.0 sy, 0.0 ni, 92.0 id, 0.5 wa, 0.0 hi, 0.5 si, 0.0 st
      MiB Mem : 8192.0 total, 4096.0 free, 3072.0 used, 1024.0 buff/cache
      MiB Swap: 2048.0 total, 2048.0 free, 0.0 used

      PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
      1234 alice 20 0 500m 200m 100m S 2.0 2.4 0:10.00 firefox
      1 root 20 0 100m 10m 5m S 0.0 0.1 0:05.00 systemd
    • Top Section: System summary (uptime, load, CPU, memory).

    • Bottom Section: Process list (PID, user, CPU/memory usage, command).

  • Navigation and Interaction

    top is interactive—use these keys:

    KeyAction
    qQuit top
    SpaceRefresh now
    h or ?Show help
    kKill a process (enter PID)
    fManage fields (add/remove columns)
    Shift + PSort by CPU usage (default)
    Shift + MSort by memory usage
    uFilter by user (enter username)

    Example (Kill):

    • Press k, enter PID (e.g., 1234), press Enter, choose signal (default 15 for SIGTERM).
  • Customizing Display

    Adjust what you see in real time.

    Change Refresh Rate:

    Press d, enter seconds (e.g., 1 for 1-second updates).

    Filter by User:

    Press u, type alice, press Enter—shows only alice’s processes.

    Add Fields:

    Press f, navigate with arrows, toggle columns (e.g., %MEM), press q to save.

  • Starting with Options

    Launch top with specific settings.

    Example (User Filter):

    top -u alice
    • Shows only alice’s processes.

    Example (PID Focus):

    top -p 1234
    • Monitors only PID 1234.

    Example (Batch Mode):

    top -b -n 1
    • Runs once (-n 1) in batch mode (-b), outputs to terminal (useful for scripts).

For more details, check the manual with man top