Last updated
Last updated
The top
command in Linux is used to display real-time system resource usage. It provides a dynamic view of processes running on the system, along with CPU, memory, and swap usage. Here’s a detailed explanation of how to use top
and what information it provides:
top
Basic Usage
To use top
, open a terminal and simply type:
By default, top
displays a continually updating list of processes ordered by CPU usage.
Options and Interactive Commands
top
provides a rich set of interactive commands and options to control its behavior and view different system metrics:
Interactive Commands
Sorting: Press P
to sort processes by CPU usage (default), M
to sort by memory usage, N
to sort by process ID, etc.
Navigation: Use arrow keys to scroll up and down through the process list.
Process Management: Press k
to kill a process, r
to renice a process (change its priority), u
to filter processes by user, etc.
Toggle Display: Press f
to toggle columns (fields) displayed, H
to toggle threads, c
to toggle full command path, etc.
Quit: Press q
to quit top
.
Options
-d <seconds>
: Specifies the delay between updates (in seconds).
-u <username>
: Displays processes for a specific user.
-p <PID>
: Monitor specific process IDs.
-b
: Batch mode. Runs top
in batch mode, useful for capturing output programmatically.
Example:
The default display of top
includes columns such as:
PID
: Process ID
USER
: User running the process
%CPU
: Percentage of CPU time used by the process
%MEM
: Percentage of memory used by the process
COMMAND
: Command name or command line used to start the process
System Monitoring: top
is invaluable for monitoring system performance and identifying processes that are consuming excessive CPU or memory resources.
Performance Analysis: Helps in troubleshooting performance issues and bottlenecks by providing real-time data on resource usage.
Process Management: Allows users to interactively manage processes, such as killing or renicing processes based on their resource consumption.
top
is a powerful and versatile command-line tool for monitoring system resources and processes in real-time on Linux systems. It provides comprehensive insights into CPU, memory, and process activity, making it an essential utility for system administrators, developers, and users troubleshooting system performance. By mastering its interactive commands and options, users can effectively manage and optimize system resources.