Top command in detail on Linux
What is Top command?
top command shows a list of processes running in your system.It gives the summary on the top,how much of your system resources are being utilised.It displays number of processes running,cpu status,free memory, PID of program,user priority, uptime,memory and cpu usage etc.
The top program provides a dynamic real-time view of a running system. It can display system summary information as well as a list of processes or threads currently being managed by the Linux kernel. The types of system summary information shown and the types, order and size of information displayed for processes are all user configurable and that configuration can be made persistent across restarts.
The program provides a limited interactive interface for process manipulation as well as a much more extensive interface for personal configuration.Open you terminal and type top
root@seven:~# top top - 09:05:51 up 1:13, 1 user, load average: 0.72, 0.32, 0.28 Tasks: 149 total, 1 running, 147 sleeping, 0 stopped, 1 zombie %Cpu(s): 11.9 us, 2.1 sy, 0.0 ni, 85.9 id, 0.0 wa, 0.0 hi, 0.1 si, 0.0 st KiB Mem: 1908416 total, 1128268 used, 780148 free, 126172 buffers KiB Swap: 1113084 total, 0 used, 1113084 free. 498036 cached Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 1156 root 20 0 2073284 232168 68632 S 56.5 12.2 1:56.49 gnome-shell 838 root 20 0 250328 35120 19392 S 6.0 1.8 0:04.54 Xorg 2150 root 20 0 441192 30028 23376 S 1.0 1.6 0:01.28 gnome-term+ 7 root 20 0 0 0 0 S 0.3 0.0 0:03.77 rcu_sched 1222 root 20 0 2441772 57392 21152 S 0.3 3.0 0:06.91 java 2160 root 20 0 25688 2984 2480 R 0.3 0.2 0:00.06 top 1 root 20 0 176152 5132 3088 S 0.0 0.3 0:01.65 systemd 2 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kthreadd
As you can see it is showing active and idle processes as well as cpu and memory usage,uptime etc.
Hide the idle processes
Just press i on your keyboard all the idle processes will be hidden and running processes will be shown.
Sort the processes according to memory usage
SHIFT + M command sort processes according to the memory usage.Process consuming highest memory will be listed first.
SHIFT + M
Sort the processes according to cpu usage
SHIFT + p will list the processes first on the basis of cpu usage.
SHIFT + P
SHIFT + W
The above command saves the top's output into a file.File will be saved in the home directory under the name of toprc.By default file will be hidden press CTR + H to make hidden files and directories visible.
One shows the detials of individual cpu's running on the system.
Z displays the running processes in colours.
d option allows us to change refreshing time.By default it refreshes in every 3 seconds,but you can customize it the way you want.
with k command you can you can kill processes.You must supply PID(Process ID) to it. You can obtain PID from the first column.Syntax:pid id
A command splits top's output into multiple screens.
c displays the absolute path of the running processes.Check the last column command
With n we can reduce the number of process to n numbers.
h is for help.It displays all the options that you can use with top.
Splits top output into multiple screens