How to Use the top Command in Linux – Guide

Linux provides a top command that provides useful statistics about system resources. You can use this command to see CPU and memory usage along with process information for running services. Additionally, you can find zombie processes using the top command. Therefore, mastering the top command is a must for Linux administrators.

To use top in a real world scenario, you will need to first create a new terminal and then type the following: top This will show you the active processes on your computer. You can then use the commands listed below to list all of the processes that are running on your computer.

How does the superior command work?

The default output of the top shows a list of running processes along with the default CPU metrics. You can think of the first part of the output as the dashboard. The lower section shows the list of processes and provides a real-time view of all running processes.

The dashboard consists of five lines, each containing some metrics. The first line shows short information about the system, such as uptime, load average, and the number of users currently connected. Tasks are shown on the second line. The third shows CPU load and the following two lines indicate memory usage.

top -n

1. View all running processes

When used with arguments, the top command displays a list of all currently running processes and their associated resources.

You can use the Up, Down, PageUp and PageDown keys on the keyboard to browse the output of the shell.

2. Sort Linux processes by PID

You can sort the list of processes by their program ID or PID. To do so, press the N key while running the top.

3. Sort processes by memory and CPU usage

CPU usage is a measure of how much time a computer is spending on specific tasks. You can sort the list by CPU usage using the M key on your keyboard. Type P to sort by CPU again.

4. Sort processes by runtime

If you want to know how long processes have been running on your machine, press the M and T keys.

5. View running processes for specific users

We can see a list of all running processes that belong to a specific user and their associated processes. If we are inside the top, we can press u, provide the username and press Enter. Alternatively, we can use the top -u option followed by the username to see this information.

The command mentioned above displays all processes invoked by the root user. ..

6. Highlight active processes

If you press the z key while inside a Linux process, it will highlight all of the processes that are currently running on your computer. This can be helpful when trying to find a specific process. ..

Final note

Linux is a versatile operating system that can be used for a variety of tasks. One of the most popular commands in Linux is the top command. This guide will teach you how to use top to monitor your computer’s performance. ..