List of content you will read in this article:
A guide using Linux’s top command
For Linux users, it’s crucial to have a good understanding of the top command’s interface, and that's not just memorizing a couple of commands. For better understanding, we will explain everything from the very start.
To begin with, you need to run the top command by typing ‘top’ in the command line and pressing enter. This command will open an interactive command line application.
The output table contains an upper section and a lower section. The first includes statistics on processes and resource usage, while the second indicates a list of currently running processors. Let’s dive right into each section.
Top’s interface: the upper section
As mentioned above, the top’s output contains two sections. The upper section contains several parts, as explained below:
In the first line, Top follows by the system uptime, which says how long your system has been up and running.
It displays the number of active users, and to get more information about active users, you can use the ‘who’ command.
Here you can see the information about your system's memory usage, and you’ll see the total, free, and used values.
The second line is the Task output, which gives you information about the processes running on your system, and it has five values as below:
Gives you info about the sum of processes from several states.
It gives you info about how many processes are handling the request and executing them.
Display the processes waiting for an operation to be fulfilled.
Display processes stopped for various reasons, such as by pressing Ctrl + Z.
To keep track of processes, the kernel keeps several data structures in memory. A process can create many child processes; each child process may exit when the parent process is still active. A process that has been terminated but still has data structures is often called a zombie process.
In the third line of the top command output, %Cpu indicates detailed information about your system's CPU.
Displays the CPU time that’s spent in user space.
Displays the CPU time that’s spent in kernel space.
Displays the CPU time that’s spent on low-priority processes.
Displays the CPU time that’s spent on IDLE.
Displays the CPU time that’s taken on your disk.
Displays the CPU time that’s spent servicing or handling hardware interrupts.
Displays the CPU time that’s spent servicing or handling software interrupts.
Displays the CPU time that’s stolen from a virtual machine.
Top’s interface: the lower section
In this part, we’ll explain the second section’s columns.
Indicates the id of the task process.
Indicates the priority of processes; the higher the number, the lower the priority.
Indicates the total memory sorted by tasks.
Indicates the username of the task’s owner.
Indicates the CPU usage.
Indicates the time duration since it started.
Indicates the shared memory size.
Indicates a nice value of the task. A positive NI value shows lower priority, and a negative NI value means higher priority.
Indicates the memory usage of a specific task.
Indicates the total usage of physical RAM, in kilobytes.
Indicates the command’s name that’s started the processes.
Top Command’s Examples
So far, we have learned about different parts of the top’s interface and how everything works there. Now it’s time to provide you with the most common Top command lines.
If you need to kill a process, simply type ‘k’ while the top runs. This will ask you for the id of the process and press enter. Next, you need to enter the process's signal that should be killed.
Sort the process list
Linux users always need a tool like Top to see which process takes more space. So, you can press the following keys to do it:
listed by memory usage.
Listed by CPU usage.
listed by process ID.
They are listed by running time.
The Top output will show all the results in descending order. And you can switch to ascending order by pressing R.
Display a list of threads instead of processes
We talked about how Linux switches between processes. Unfortunately, processes do not share a memory or other resources, which makes switching between processes quite slow.
Like many other operating systems, Linux offers a “lightweight” alternative called a “thread, " which can share memory and other resources with processes. There is no way to separate them from a process, but they can run concurrently as processes can, even though they share certain memory regions and resources.
To switch back to the process view, press ‘H’. Plus, use the -H to display threads by default.
Syntax: top -H
Display full paths
The top doesn’t display the full paths or distinguish between kernel-space and user-space processes. To get this info, press ‘c’ while Top is running.
To display the child-parent hierarchy of processes, press ‘v’ while Top runs.
List process from a certain user
Suppose you want to list the processes from a user, press ‘u’ while Top is running. Next, type the username. Alternatively, you can leave it blank to see the processes of all users.
A simple sorted list will not be sufficient if you have plenty of processes to work with. You can use Top's filtering mode to focus on a few processes instead of a bunch. Press the ’O’ key to activate this mode. A prompt appears at the Top where you can type a filter expression. This statement specifies the relationship between an attribute and a value.
Change the look of the CPU and Memory statistics.
You may not be comfortable with Top's default way of showing CPU and memory statistics if you’ve gotten used to a GUI environment. To change the appearance of CPU and memory statistics, you can press the keys 't' and 'm’. Pressing these keys will allow you to switch between four different views. The progress bar will move back and forth between two different types on the first two presses.
You can save any changes you’ve made by pressing ‘w’.
What is the main purpose of the Linux Top command?
The main purpose of the Linux Top command is to provide a dynamic and real-time view of a running system, including information about process activities and system resource utilization.
How can I view detailed information about a specific process using Top?
You can view detailed information about a specific process using Top by pressing ‘F’ to display the Process Field List, then selecting the PID (Process ID) of the desired process.
Does the Linux Top command have any configuration options?
Yes, the Linux Top command has various configuration options that can be accessed by pressing 'O' (for Options) when running Top, allowing users to customize what information it displays.
Is it possible to interact with processes using Top?
Yes, it is possible to interact with processes using Top by pressing ‘k’ (for Kill), entering the process ID, selecting it from a list, and then confirming the action.
What type of system resources are monitored by Linux Top?
The Linux Top command monitors system resources such as CPU usage, memory usage, swap utilization, load average, virtual memory statistics, uptime, number of users currently logged in, and more.
- Linux’s Top command allows users to monitor their system’s resource usage in real-time.
- The Top command is commonly used to troubleshoot performance issues.
- The upper section of the Top command mostly shows you info about the CPU and its processes. At the same time, the lower section is mostly concerned with RAM usage. we offer that you buy cheap linux vps and you practice.
People also read: