How to use TOP command

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

Introduction

Administrators should know what processes are running and the consumption of each of them.

That’s why you need tools to help you to monitor your system and watch the utilization of it, and as a result you tune your system better to make greater use of it by killing unneeded processes or give priority to the important ones.

One of the tools (commands) to do so is TOP command and this article is for how to use TOP command in your Linux-based system.

There are lots of commands that help you monitor your system, as an example there is PS, but the different here is that PS is for non-interactive monitoring.

What is TOP command?

Table Of Process or as common TOP is used to show the active Linux processes. It provides a dynamic real-time view of the running system. Usually, this command shows the summary information of the system and the list of processes or threads which are currently managed by the Linux kernel.

How to use TOP command

Simply run TOP command to get your running processes view

once you run the command you get the previous view, and here we need to clarify the shown items

PID: the process unique ID

USER: the owner of the process

PR: the process priority

NI: displays the nice value of the process

VIRT: amount of virtual memory used by the process

RES: actual consumption of physical memory

SHR: shared memory size

S: which state the processes is in

%CPU: percentage of CPU usage

%MEM: percentage of memory usage

TIME+: CPU time

COMMAND: the command name

To quit TOP command press q key

Organize your output

to sort out your processes by memory usage press M

press P to sort out by CPU usage

by process ID (PID) press N

Note that TOP command sort out in descending order by default, to sort out in ascending order press R

if you want to view processes order by running time press T

Also you can sort out by any of the previous parameters in the TOP command itself by running the following command:

CPU as an example

top -o %CPU

to view the full path of the command press c

also you can get the same result by running this command

top -c

To see the hierarchy or the tree of each process press V

list the processes of a specific user

You can do that by one of two ways

1. by pressing u in the top command and specify the username

2. by running top command with the following option

top -u root

Set refresh interval

by default the refresh interval is 3.0 seconds, you can change it by pressing d

Highlight the running processes

press z to identify the running processes

List idle/sleeping processes

press i

Take some actions!

Killing a process

first find the PID of the process you want to kill then press k and enter the PID, the default will be the process that is currently selected

Renice a process

The nice value is used to identify the priority of a process, negative value means higher priority and of course positive value means lower priority, nice value range is from -20 to 19

to renice a process press r

And finally to get help press h

Conclusion

TOP command is very useful and powerful tool to monitor, optimize and manage your system processes and it has a lot of options to use and we covered the common ones.

To get more help man the command and see the documentation of it.

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"
Mel
Melhttps://unixcop.com
Unix/Linux Guru and FOSS supporter

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest articles

Join us on Facebook