When using Linux, the top command is a useful tool for keeping an eye on what processes are active and how much of the system’s resources they are using. Having a real-time view of your Linux system’s activity will allow you to more easily identify resource-intensive programs and terminate them. In this tutorial, we’ll go through the top command in Linux and how to use it to get detailed information on the processes currently operating on your machine.
Basic Top Usage
To access Linux’s top tool, open a terminal and type top:
Here is an example of the results of the top command:
There are two parts to the output:
The resource utilization, including that of the CPU, RAM, and disk, is shown in the upper part.
The bottom part displays data about the currently active processes and information like process ID, username, and process name.
Filtering Specific Processes
To restrict the top output to a particular process, hit the O key and enter COMMAND=name. Here, the name denotes the name of the process.
As an illustration of system filtering, consider:
Filtering User Processes
In this case, only processes belonging to the Ubuntu user would be seen.
Sorting Tasks Based on Their CPU Usage
Changing the Refresh Interval
In its default setting, the top will automatically update its display every three seconds. While the top is running, using the d key will allow you to change this setting.
Displaying the Binary’s Path
Hit the c key to see the path to the command that started a certain process:
Saving The Output to a File
Additionally, using redirection indicators, we can save the file’s output. for instance, to save the top data for 10 minutes, you may type:
You may specify the number of iterations to do before quitting using the -n option.
With the -b option, the top enter batch mode and keeps processing the output until the max number of iterations has been reached (as indicated by the -n option).
To summarize, if you’re a system administrator or just curious about which programs are draining your computer’s resources, top is a useful tool. The top documentation is a great resource for anyone interested in learning more about the “top”.