Linux Tutorial
Linux File/Directory Management
Linux Packaging And Compression
Vim Text Editor
Linux Text Processing
Linux Software Installation
Linux User/User Group Management
Linux Permission Management
Linux Filesystem Management
Linux Advanced Filesystem Management
Linux System Management
Linux Backup and Recovery
Linux System Service Management
Linux System Log Management
Linux Boot Management
LAMP/LNMP Environment
SELinux Management
In this tutorial, we will cover the top
command in Linux. The top
command is a system monitoring tool that provides a dynamic, real-time view of the processes running on a system. It displays information about the system's performance, such as CPU usage, memory consumption, and overall system load.
Basic Usage of the top Command
To start using the top
command, simply enter top
in your terminal:
top
The top
command will display an updating list of processes, sorted by the percentage of CPU usage. The display consists of two main sections: the system summary, which is shown at the top of the screen, and the process list, which occupies the rest of the screen.
Understanding the System Summary
The system summary section displays information about the system's overall performance, such as:
load average
: the average number of processes in the run queue over the last 1, 5, and 15 minutes.Tasks
: the total number of processes, and their states (running, sleeping, stopped, or zombie).Cpu(s)
: the percentage of CPU usage for user processes, system processes, and idle time.Mem
: the total memory usage, including used, free, and cached memory.Swap
: the total swap usage, including used and free swap space.Navigating the Process List
The process list section displays information about each process, such as:
PID
: the process ID.USER
: the user who owns the process.PR
: the process priority.NI
: the nice value of the process (used to determine its priority).VIRT
: the virtual memory used by the process.RES
: the resident (physical) memory used by the process.SHR
: the shared memory used by the process.S
: the process state (R = running, S = sleeping, T = stopped, or Z = zombie).%CPU
: the percentage of CPU usage by the process.%MEM
: the percentage of memory usage by the process.TIME+
: the total CPU time used by the process since it started.COMMAND
: the name of the command that started the process.Interactive Commands in top
The top
command allows you to interact with the display using various keyboard commands:
q
: Quit top
.h
: Display help (list of available commands).k
: Kill a process by entering its PID.r
: Renice a process by entering its PID and the new nice value.u
: Show only processes owned by a specific user.M
: Sort the process list by memory usage.P
: Sort the process list by CPU usage (default).T
: Sort the process list by time (cumulative CPU time).m
: Toggle the display of memory information in the system summary.t
: Toggle the display of CPU information in the system summary.Summary
The top
command in Linux is a powerful system monitoring tool that provides a dynamic, real-time view of the processes running on a system. By understanding the information displayed in the system summary and process list sections, and using various interactive commands, you can effectively monitor and manage your system's performance.
How to use the Linux top
command:
top
command in Linux is a dynamic and interactive tool that provides real-time information about system processes and resource usage.# Example: Running the top command top
Real-time process monitoring with top
in Linux:
top
continuously updates and displays real-time information about processes, system load, and resource usage.# Example: Real-time process monitoring with top top
Interpreting the output of the top
command:
top
output includes information about CPU usage, memory usage, running processes, load averages, and more.# Example: Interpreting the top output top
Sorting and filtering processes in top
:
top
allows sorting processes by various criteria and filtering based on user-defined parameters.# Example: Sorting processes by CPU usage top -o %CPU # Example: Filtering processes by user top -u username
CPU and memory usage analysis using top
:
top
provides detailed information on CPU and memory usage, aiding in performance analysis and troubleshooting.# Example: Analyzing CPU and memory usage with top top
Killing processes from within the top
command:
top
allows sending signals to processes, including terminating or killing them.# Example: Killing a process from top top, select the process (k key), enter the signal (default is 15 for SIGTERM)
Customizing the display in top
on Linux:
top
provides options to customize the display, including changing the columns shown, adjusting refresh rates, and more.# Example: Customizing the top display top -d 5 # Set a refresh rate of 5 seconds
Monitoring specific users or processes with top
:
top
can be configured to monitor specific users or processes by applying filters.# Example: Monitoring processes of a specific user top -u username
Continuous process tracking with top
:
top
continuously tracks and updates the display, providing a real-time view of the system's status.# Example: Continuous process tracking with top top