Top is a Linux process and resource usage monitoring utility. It allows users to view real-time information about the running processes and threads managed by the system’s kernel. Because of its interactivity, top enables users to perform tasks, such as filtering for specific processes, filter processes by users, PID, and kill processes.
This guide will walk you through the basics of using the ps command to locate specific information about the system.
Basic Top Utility Usage
To launch the top utility, use the top command in the terminal. Using this command will spawn an interactive session showing system resource usage and running processes:
The upper part shows the resource usage. This output is similar to that of uptime and the free command in Linux.
To turn these values off, press “m” to hide the memory usage information and “l” to hide the uptime information.
To scroll through the running processes, use the up and down arrow key. To quit, press “Q”.
The lower part of top command contains information about running processes. Let us focus on this.
The output uses a column-based organization, with an identifier on each:
- PID: This column shows the unique ID of each process.
- PR: This column shows the priority of the task.
- NI: This column shows the nice value of the process. A positive value indicates low priority, while a negative value indicates high priority.
- VIRT: This column represents the total virtual memory used by the process.
- RES: This column shows the total actual memory used by the process.
- SHR: This column shows the total amount of shared memory used by the process.
- S: This column shows the process state in a single letter.
- %CPU: This column shows percentage CPU usage per process.
- %MEM: This column shows percentage Memory usage.
- TIME+: This column shows CPU time used by the process calculated to hundredths of a second.
- COMMAND: This column shows the process name.
How to Make Top Filter Processes by Memory Usage
You can also filter processes by memory usage in top. To do this, press SHIFT + m as shown:
Top will filter the processes by memory usage in descending order. Doing this can help identify the process using the most memory, giving you a chance to take action.
To filter by actual memory usage, use the command:
Similarly, the command will filter the memory usage in descending order.
You can also interactively choose the filter parameter. To do this, press SHIFT + F and select MEM as:
How to Filter Process by User
To show processes from a specific user, use the command:
For example, to show processes from the ubuntu user; enter the command:
How to Show the Parent and Child Processes
To show the parent and child processes while top is running, press V. This will give you an output similar to the one shown below:
How to Kill All Processes
To kill a process in top, press k and enter the PID of the process.
Press enter to execute the kill command. This will terminate the process with the specified PID.
Top is a handy utility that makes it possible to understand and manage the Linux System processes. Besides what we have discussed in this tutorial, top has tons of other functionalities.
To understand how you can customize and use top to its full potential, consider the manuals.