The top
command is a powerful utility in Linux used for monitoring system resources and displaying real-time information about running processes. It provides a dynamic, interactive view of the system’s CPU usage, memory usage, process statistics, and other essential system metrics. The top
command continuously updates its display to reflect the current state of the system.
When you run the top
command, you’ll see a live, scrolling display that includes information such as:
- System summary: It shows system-level information, including uptime, number of users, load averages, and overall CPU and memory usage.
- Process listing: It displays a table of running processes, showing details such as the process ID (PID), user, CPU usage, memory usage, process status, and execution time.
- CPU usage: It provides a breakdown of CPU usage, both in terms of overall usage and the individual usage of each process.
- Memory usage: It shows the system’s memory usage, including the total amount of memory, used memory, free memory, and memory usage by individual processes.
- Interactive controls:
top
allows you to interact with the displayed information. You can sort the process list based on various criteria (e.g., CPU usage, memory usage), change the update interval, filter processes, send signals to processes, and more.
Here are some useful keyboard shortcuts available in top
:
- Pressing
q
will exittop
. - Pressing
k
allows you to enter the PID of a process you want to kill. - Pressing
r
toggles the renice command, allowing you to change the priority of a process. - Pressing
f
lets you toggle and customize the displayed fields. - Pressing
o
allows you to interactively specify the sort column for the process list.
The top
command provides real-time insights into system performance and process monitoring. It is particularly useful for troubleshooting high CPU or memory usage, identifying resource-intensive processes, and observing system behavior over time.
For a more detailed understanding of the top
command and its available options, you can refer to the manual page by typing man top
in your terminal.
How to use Linux top command
Let’s explore a detailed example of how to use the top
command in Linux.
- Running the
top
Command:
Open a terminal and simply typetop
to run the command. Thetop
utility will start displaying real-time information about the system’s resource usage and running processes.
2. Understanding the Display:
The top
display consists of multiple sections, including the system summary, CPU usage, memory usage, and the process table.
- System Summary: The top line of the display provides an overview of system-level information, including uptime, number of users, load averages, and overall CPU and memory usage.
- CPU Usage: The CPU usage section displays the current CPU utilization, as well as the individual CPU cores’ usage. It shows the percentage of CPU time used by different processes.
- Memory Usage: This section shows the system’s memory usage, including the total amount of memory, used memory, free memory, and memory usage by individual processes.
- Process Table: The largest section of the display is the process table, which lists the running processes. It includes details such as the process ID (PID), user, CPU usage, memory usage, process status, and execution time. The processes are sorted by default based on the CPU usage in descending order.
3. Navigating and Interacting with top
:
- Use the arrow keys (up and down) to scroll through the process table.
- Press
k
to enter the PID of a process you want to kill. You will be prompted to confirm the action. - Press
r
to toggle the renice command, allowing you to change the priority of a process. Enter the PID and the new priority when prompted. - Press
f
to toggle and customize the displayed fields. You can select which columns to display and change their order. - Press
o
to interactively specify the sort column for the process list. You can choose a different field to sort the processes, such as memory usage or process name.
- Exiting
top
:
To exit thetop
command, pressq
.
The top
command provides a comprehensive and real-time overview of system performance, CPU usage, memory usage, and running processes. It allows you to monitor the system, identify resource-intensive processes, and take necessary actions to optimize system performance.
Remember that top
provides a wide range of interactive features and keyboard shortcuts. For a complete list of available options and their usage, you can refer to the manual page by typing man top
in your terminal.