Linux top Command: Monitor Processes in Real Time

top is an interactive tool that repeatedly updates CPU and memory usage as well as process status. You can see in real-time which tasks are using resources when the server slows down.

At the top, there is a summary of system load, CPU, and memory, and below that, the figures for each process are displayed. It is important to look at patterns that persist over several updates rather than a single high value. To exit, press q within the screen.

Basic syntax

top [option]

Installed implementations and options may vary depending on the distribution. Check the description for your current system with man top.

Examples

Viewing the real-time list

Exit by pressing q during execution, and you can change the sorting based on CPU or memory with P and M.

top

Observing a specific PID

Focus on the resource changes of a process you have already found.

top -p 1234

Print only once

When an interactive screen is not needed, record only one iteration in batch mode.

top -b -n 1

Values to view first on the real-time screen

When you run top, the top shows the load average and a summary of CPU and memory, while the bottom periodically updates each process's PID, CPU usage, and memory usage. In batch mode, you can receive a single screen as text.

top -b -n 1 | head -n 8

Structure of the example screen (numbers vary depending on the system):

top - ... load average: ...
Tasks: ... total, ... running
%Cpu(s): ... us, ... sy, ... id
MiB Mem : ... total, ... free, ... used
    PID USER      %CPU %MEM COMMAND

Do not determine a problem solely based on %CPU; consider the duration and the role of the process as well. On the interactive screen, you can sort by CPU with P, sort by memory with M, and exit with q. The display units and columns may vary depending on the implementation and settings.

Main Options and Format

Options/Format Description
-p PID Observe only the specified PID.
-d seconds Set the screen refresh interval.
-b Use batch output mode.
-n count Refresh the specified number of times.

Precautions when using

The initially displayed CPU usage and cumulative time are affected by the observation point and calculation method. If a single process uses multiple cores, the display may exceed 100%. The exit command inside top affects the actual process, so check the target PID before using it.

Frequently Asked Questions

How do I exit from top?

Press q in the interactive screen. This is an operation inside top, not a shell command entered in the terminal.

Official Documentation

You can check the exact behavior of the options and differences depending on implementation in the official documentation for top.