top Command in Linux | Explained

In Linux, various processes run in the background, such as processor activities and Kernel tasks. To view and manage these services, we use the top utility. The top is the built-in utility for viewing the real-time processes and threads of the Kernel-related tasks. Primarily, Linux system administrators use the top utility.

The usage of the top command in Linux will be demonstrated in this post.

How is the top Command Used in Linux?

For using the top utility in Linux, various options can be utilized with the top command. The list of options can be viewed via the following command:

$ man top

The purpose and the syntax could be seen on the first screen of the output.

In the output, scroll down, and you will see the list of options and their usage as seen below:

Now, let’s get into the examples of the top command.

Example 1: Listing All Running Processes

To list down all the processes of Linux, simply run the “top” command in the terminal:

$ top

All the running processes have been listed.

Example 2: Listing All Running Processes For Particular User

To list the processes for the particular user, use the “u” flag with username as follows:

$ top -u itslinuxfoss

The above image shows that the processes for the particular user (itslinuxfoss) have been listed.

Example 3: Highlighting the Running Processes

To highlight the running processes, list the processes using the “top” command and press the “Z” button from the keyboard:

The running processes are highlighted.

Example 4: Displaying the Path of the Running Processes

To display the path for the running processes, press the “C” button after listing the processes:

The processes with the absolute path have been listed.

Example 5: Refreshing the Time Interval

When you list the process using the top command, it can be noticed that processes are refreshing after the 3 seconds of the time interval. It is the pre-default time interval set by the Linux operating system. To change the time interval, press the “D” button, and it will ask you to enter the time interval. Type the time in seconds and hit the enter button:

After pressing the enter button, the time interval will be applied.

Example 6: Killing Any Process with PID

To kill any process with its process ID, press “K” from the keyboard. It will ask you to enter the process ID, or you can kill the default process ID given by the system. Hit the enter button after putting the Process ID:

The specific process will be killed.

Example 7: Sorting the Processes By Process ID

To sort the processes by process ID, press the “M” and “T” buttons from the keyboard:

The process will be sorted out as shown in the above image.

Example 8: Reince the Process

To “Reince” (giving the new ID based on priority) the process, you can press the “R” button from the keyboard. It will display the process with its default ID, enter the new ID, and hit the enter button:

The new ID will be applied to the process.

Example 9: Displaying the Cores of the CPU

Using the top command, the user can also get the number of cores in the operating system. To do so, press “1” on the keyboard:

The system has 2 CPU cores that are highlighted in the image.

Example 10: Displaying Idle Processes

To display the idle processes of the Linux Kernel module, press the “i” button from the keyboard:

All the idle processes will be listed.

Example 11: Getting Help For the top Command

For displaying the help of using the top utility, press “H” from the keyboard:

All the options for using the top command will be listed.

That’s all from the top command.

Conclusion

The top is the built-in utility of the Linux operating system that is utilized for displaying the processes of the processor activities and the Kernel tasks. The output of the top utility depends upon the various options that have been implemented in the post. This write-up has briefly illustrated the usage of the top utility in Linux.