
The top command in Linux displays real-time system information, including running processes, active users, and resource utilization such as CPU and memory. You can use top to monitor, troubleshoot, and identify performance issues in your system.
This article explains how to use the top command in Linux.
top Command SyntaxThe following is the basic syntax of the Linux top command:
In the above command, options modify the command's behavior to customize the output.
top Command OptionsThe following are the most common Linux top command options:
Check out how to use the tar command in Linux for quick file archiving and unzipping.
top Command InterfaceThe top command interface continuously displays a list of processes and information about CPU usage, memory usage, load averages, and other system statistics by default. The list shows the most resource-intensive processes at the top.
Run the top command without any options to access the default interface to view the system processes, CPU, and memory usage.
Output:
Press Ctrl or Q to exit the interface.
top Command InterfaceThe top command interface has the following sections:
System Information: Displays general information about the system, including uptime, number of active users, load averages, and number of running processes.
For example:
Task Summary: Displays a summary of the total active tasks including the number of processes and their status.
For example:
System Process List: Displays detailed information about each process, including the PID, user, CPU usage, memory usage, and command information.
For example:
Within the above section, each header represents a specific value as described below:
KBs (Kilobytes).KBs (Kilobytes).CPU Usage: Displays the CPU usage statistics including the time spent on system processes and the average Input/Output (I/O) processing time.
For example:
In the above output:
us: Time spent on user processes.sy: Time spent on system (kernel) processes.id: Idle time.wa: Time spent waiting for I/O operations to complete.Memory Usage: Displays the system's memory usage statistics, including the used and available memory.
For example:
In the above output:
total: Total available memory.used: Used memory.free: Free memory available for processes.buff/cache: Memory used for buffers and cache.top Command in Linux with ExamplesThis section uses practical examples to show you how to use the Linux top command. Follow the steps below to run the samples.
Pass the -c flag to display the process command name instead of arguments making the processes list more readable.
Output:
Set the delay interval between updates in seconds. For example, 5 seconds.
Output:
Monitor specific process IDs. For example, 1234 and 5678.
Output:
Run top with a specific number of iterations before exiting. For instance, 10 iterations.
Output:
Run the top command in batch mode and forward the interface's output to a file such as top_output.txt.
Output:
Display specific user's processes. Replace username with the target user.
Output:
Ignore and hide idle and zombie processes from the top interface.
Output:
Sort processes by memory usage in descending order.
Output:
Display individual threads.
Output:
top Command InteractivelyCustomize the top command interface with the following options to view and manage processes:
top Command OptionsThe Linux top command supports more advanced options to customize the output, as illustrated below:
Run top in secure mode to hide or mask certain information. For instance, hide the commands for each process.
Output:
Press V within the top interface to view processes in a tree structure.
Press Z on your keyboard to modify the display color.
Follow the steps below for additional customizations and color selections.
Press Z to access the color settings page.
Press any of the following keys to modify the target display field's color:
Select a target color to apply on the display field:
0 = black 1 = red2 = green3 = yellow4 = blue5 = magenta6 = cyan7 = white Press Enter to confirm your selection and apply changes to your top interface.
Use the following keys to customize the top command interface:
f: Displays the top configuration screen to toggle columns on or offd: Select or deselect columns.
Run the top command and press P to monitor and sort processes by CPU usage.
Run the top command and press M to find memory hogs and sort processes by memory usage.
Run the top command, press K, and enter a signal to kill a process using the PID.
You have used the top command in Linux to monitor system processes. The top command is a powerful tool for monitoring system performance and managing active processes in real time. Use the tool to manage, troubleshoot, and identify performance bottlenecks in your server. For more information, run the man top command.
0 Comments
Be the first to comment and share your perspective with the community.