Wednesday, 7 December 2016

TOP Command in Linux

Top is an utility provided by Linux. It gives completes analysis of all the process running in the system like all the active process. Also it tells about system performance like CPU, Memory utilisation. Some of the commands are:

shift + M - List process according to memory usage
shift + P - List the process according to CPU usage
Shift + W - For saving top output to a file.

EXAMPLE:

top - 04:38:00 up 10 days, 13:23,  1 user,  load average: 0.00, 0.01, 0.05
Tasks:  90 total,   2 running,  88 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem :  1014976 total,   116512 free,    93008 used,   805456 buff/cache
KiB Swap:        0 total,        0 free,        0 used.   628588 avail Mem

  PID USER      PR  NI    VIRT    RES    SHR S %CPU %MEM     TIME+ COMMAND
14446 postgres  20   0  279896   2236   1472 S  0.3  0.2   5:04.70 postgres
    1 root      20   0  128092   6700   3944 S  0.0  0.7   0:27.88 systemd
    2 root      20   0       0      0      0 S  0.0  0.0   0:00.10 kthreadd
    3 root      20   0       0      0      0 S  0.0  0.0   0:01.29 ksoftirqd/0
    7 root      rt   0       0      0      0 S  0.0  0.0   0:00.00 migration/0
    8 root      20   0       0      0      0 S  0.0  0.0   0:00.00 rcu_bh
    9 root      20   0       0      0      0 R  0.0  0.0   1:26.88 rcu_sched
   10 root      rt   0       0      0      0 S  0.0  0.0   0:03.87 watchdog/0
   12 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 khelper
   13 root      20   0       0      0      0 S  0.0  0.0   0:00.00 kdevtmpfs
   14 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 netns
   15 root      20   0       0      0      0 S  0.0  0.0   0:00.01 xenwatch
   16 root      20   0       0      0      0 S  0.0  0.0   0:00.00 xenbus
   18 root      20   0       0      0      0 S  0.0  0.0   0:00.14 khungtaskd
   19 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 writeback
   20 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 kintegrityd
   21 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 bioset
   22 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 kblockd
   23 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 md
   28 root      20   0       0      0      0 S  0.0  0.0   0:00.24 kswapd0
   29 root      25   5       0      0      0 S  0.0  0.0   0:00.00 ksmd


Below are the few description of the contents of TOP Command:

Job - Present time, how much time system is up, how many users connected, load average.

Task - How many total tasks, how many tasks running, how many tasks sleeping, how many tasks stopped, how many zombie process.

CPU - % of CPU used by users, % of CPU used by system, % of CPU used by nice value, idle CPU %, % of CPU wating for IO(to write), % of CPU used by Hardware Interupt, % of CPU used by Software Interupt, Steal time - used when there is a virtual box( delay in getting the actual CPU by virtual CPU in virtual systems)

Memory - Total RAM, Memory Used (Actually used - buffer), Memory Free( Actual + buffer + cache from swap) , Buffer( when system have free memory, it extracts few pages and keep it in buffer for caching, if system needs, it will give back the pages from buffer)

Swap- Total Swap, Swap Used, free, caching

PID - Process ID
USER - user through which process are running
PR - Priority - Process priority. 0 - highest priority 40 - Lowest
NI - Nice value - CPU Scheduling Priority. Utility through which we can set the priority manually. -19 -highest priority 20 - lowest priority
Virtual Memory - Each process cant access direct physical memory, so it uses virtual memory. Each process have its own virtual space. Physical memory address space is mapped to virtual memory address space. It is sort of security restriction where process cant directly indulge with Physical RAM. MMU - Memory Management Unit does the mapping between physical address space to virtual address space. pmap 1 shows mapping between VAS to PAS.
Resident Memory - Total Physical Memory that is non swapped.
Shared Memory - Memory that is being shared by other processes
S - state - Sleeping or running
% CPU - % of CPU used by the process
% MEM - % of Memory Used by the process
Time - How long is the process running
Command - What is the command that is being executed.

C - Process with obsolete path
k <pid> - to kill a process
z - Change color of top
r - for re nice a value
1 - shows the number of CPU
d - change refresh rate - Default 3 sec
A - Splits screen into multiple part/screen. Top Right Side says which split screen I am. So accordingly we can sort per split screen. Goto different split screen using a. Shift + a will toggle screen from small to big.
h - help
n - Reduce the number of listed process to n
I - To hide load average line
t - to hide CPU states. 2nd and 3rd line.
m - to hide/show the memory line. 4th and 5th.
top -u postgres or top and press u
top -n 2 stops refresh after 2 sec
top -p pid, pid
top -b -n 1
top -d3 -b -n 2  > top_output.txt.
top -H -p pid
Shift F - add extra column as required. 

No comments:

Post a Comment