10 examples to help you understand top command usage in Unix/Linux

Follow below link to get a step by step illustration to permanently add or remove extra columns to top command ouput with examples

How to reduce and/or add more columns or fields to top command in Linux (swap, memory, etc)

top is one of my favourite tool for monitoring system usage and also to make any change for improving system
performance.
Let me show you some examples on the usage of top command

Intro:
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 tasks currently being managed by the Linux kernel.  The types of system summary information shown and the types, order and size of information displayed for tasks are all user configurable and that  configuration can be made persistent across restarts.

1. Without any arguments

[deepak@server1 ~]$ top
top - 17:51:07 up 1 day,  2:56, 27 users,  load average: 5.33, 29.71, 28.33
Tasks: 1470 total,   1 running, 1469 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.0%us,  0.1%sy,  0.0%ni, 99.9%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:  264114424k total, 253006956k used, 11107468k free,    66964k buffers
Swap: 33554424k total,     3260k used, 33551164k free, 245826024k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
 1960 deepak  15   0 30452 3220 1540 R  2.3  0.0   0:00.78 top
 2457 root      11  -5     0    0    0 S  2.3  0.0  11:36.93 kacpid
 2493 pmartprd  16   0 1397m 289m 9.8m S  0.3  0.1  18:36.07 pmrepagent
 4639 pmartprd  15   0  787m  54m 4080 S  0.3  0.0   5:19.55 pmserver
14402 root      RT   0  151m 5256 2872 S  0.3  0.0   1:41.40 multipathd
17886 root      10  -5     0    0    0 S  0.3  0.0   0:07.41 kondemand/11
Generally I use top without any arguments, but the magic is mostly done from the top command line which must of us skip. Well before taking you to that part let me explain you the various system related features which are shown by top command

NOTE: You can enable or disable the marked blue line by pressing "l" once top is running
top - 17:51:07 up 1 day,  2:56, 27 users,  load average: 5.33, 29.71, 28.33
Tasks: 1470 total,   1 running, 1469 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.0%us,  0.1%sy,  0.0%ni, 99.9%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:  264114424k total, 253006956k used, 11107468k free,    66964k buffers
Swap: 33554424k total,     3260k used, 33551164k free, 245826024k cachedExplanation: This line tells you about the uptime of your system along with load average value.

NOTE: You can enable/disable the marked blue line by pressing "t"
top - 17:51:07 up 1 day,  2:56, 27 users,  load average: 5.33, 29.71, 28.33
Tasks: 1470 total,   1 running, 1469 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.0%us,  0.1%sy,  0.0%ni, 99.9%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st

Mem:  264114424k total, 253006956k used, 11107468k free,    66964k buffers
Swap: 33554424k total,     3260k used, 33551164k free, 245826024k cachedExplanation:  This line gives us a brief detail of all the tasks running/sleeping/stopped currently in the system along with the CPU Usage

Value
Meaning
us
user cpu time (or) % CPU time spent in user space
sy
system cpu time (or) % CPU time spent in kernel space
ni
user nice cpu time (or) % CPU time spent on low priority processes
id
idle cpu time (or) % CPU time spent idle
wa
io wait cpu time (or) % CPU time spent in wait (on disk)
hi
hardware irq (or) % CPU time spent servicing/handling hardware interrupts
si
software irq (or) % CPU time spent servicing/handling software interrupts
st
steal time - - % CPU time in involuntary wait by virtual cpu while hypervisor is servicing another processor (or) % CPU time stolen from a virtual machine

NOTE: You can enable/disable the marked blue line by pressing "m"
top - 17:51:07 up 1 day,  2:56, 27 users,  load average: 5.33, 29.71, 28.33
Tasks: 1470 total,   1 running, 1469 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.0%us,  0.1%sy,  0.0%ni, 99.9%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:  264114424k total, 253006956k used, 11107468k free,    66964k buffers
Swap: 33554424k total,     3260k used, 33551164k free, 245826024k cached
Explanation:  The next line shows your memory(RAM and swap) usage and capacity.

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
13916 stmprd    18   0  903m 129m 9936 S 51.4  0.1   3:07.01 java
13921 stmprd    18   0  901m 128m 9936 S 49.8  0.0   3:02.92 java
13825 stmprd    18   0  951m 190m 9932 S 49.5  0.1   3:07.13 java
13856 stmprd    20   0  978m 197m 9936 S 49.2  0.1   3:05.89 java
13853 stmprd    18   0  921m 150m 9932 S 48.5  0.1   3:09.14 java
13875 stmprd    18   0  907m 132m 9940 S 48.5  0.1   3:09.49 java
13937 stmprd    25   0  926m 165m 9936 S 48.2  0.1   3:10.31 java
13919 stmprd    18   0  917m 153m 9936 S 47.5  0.1   3:05.92 java
13879 stmprd    25   0  921m 160m 9936 S 47.2  0.1   3:08.43 java
13908 stmprd    25   0  901m 131m 9932 S 47.2  0.1   3:12.23 java
13905 stmprd    25   0  907m 137m 9932 S 46.6  0.1   2:59.85 java

The left sections shows you the details of the process running along with the below details

Fields/Column
Description
PID
Process Id
USER
The effective user name of the task's owner
PR
The priority of the task
NI
The nice value of the task.  A negative nice value means higher priority, whereas a positive nice value means lower priority.  Zero in this field simply means priority will not be adjusted in determining a task's dispatchability
%CPU
The task's share of the elapsed CPU time since the last screen update, expressed as a percentage of total CPU time.
%MEM
A task's currently used share of available physical memory
TIME+
Total CPU time the task has used since it started
S
The status of the task which can be one of:
             'D' = uninterruptible sleep
             'R' = running
             'S' = sleeping
             'T' = traced or stopped
             'Z' = zombie
RES
The non-swapped physical memory a task has used
SHR
The amount of shared memory used by a task
Command
Display the command line used to start a task or the name of the associated program

2. Arrange Tasks with High to Low CPU Usage

Press "P" or "shift+p" once top is running to arrange all the tasks with High to Low CPU Usage as shown below
top - 18:03:00 up 1 day,  3:08, 27 users,  load average: 12.54, 32.34, 32.75
Tasks: 1485 total,   3 running, 1482 sleeping,   0 stopped,   0 zombie
Cpu(s): 41.2%us,  0.8%sy,  0.0%ni, 56.6%id,  1.4%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:  264114424k total, 258863028k used,  5251396k free,    76308k buffers
Swap: 33554424k total,     3256k used, 33551168k free, 250950544k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
 9663 stmprd    22   0  902m 301m 9888 S 2578.3  0.1   2:27.04 java
32117 etlprd    18  -1 32416 5908 1716 R  6.2  0.0   0:04.84 cleanup_dirfile
10053 root      18  -1 27100 1936 1460 S  4.9  0.0   0:00.15 ps
 5456 pmartprd  16   0 1182m 130m 8560 S  3.9  0.1  38:39.72 pmserver
17492 deepak  16   0 30592 3388 1544 R  3.6  0.0   0:17.11 top
 2843 pmartprd  15   0  730m  48m 4052 S  3.3  0.0   4:40.33 pmserver
 2457 root      11  -5     0    0    0 S  2.9  0.0  11:42.39 kacpid
 3731 tdmsprd   15   0  370m  49m  32m S  2.3  0.0   0:00.64 pmdtm.orig
 

3. Arrange Tasks with High to Low Memory Usage

Press "M" or "shift+m"once top is running to arrange all the tasks with High to Low Memory Usage as shown below
top - 18:04:26 up 1 day,  3:09, 27 users,  load average: 37.12, 34.56, 33.44
Tasks: 1676 total,   1 running, 1675 sleeping,   0 stopped,   0 zombie
Cpu(s):  2.3%us, 76.7%sy,  0.0%ni, 19.7%id,  1.3%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:  264114424k total, 262605184k used,  1509240k free,    77924k buffers
Swap: 33554424k total,     3256k used, 33551168k free, 252198368k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
 1852 pmartprd  18   0 2005m 319m 4776 S  6.9  4.1  28:34.32 java
 2493 pmartprd  16   0 1397m 289m 9.8m S  0.0  4.0  18:37.79 pmrepagent
20557 etlprd    15   0  911m 201m 3024 S  0.0  3.0  17:09.02 pmdtm.orig
18778 root      RT   0  286m 188m 156m S  0.0  2.1  13:24.98 aisexec
 5456 pmartprd  15   0 1182m 130m 8560 S  6.2  1.1  38:40.58 pmserver
16004 etlprd    14  -1  179m  83m 2636 S  0.0  0.1   9:41.36 db2bp
11272 stmprd    25   0  906m  67m 9736 S 99.7  0.0   0:48.11 java

4. Change the nice value (priority) of any task

To understand what is nice value follow the below link
What is nice and how to change the priority of any process in Linux?

Press "r" when top is running on the terminal. You should get a prompt as shown below in blue color

top - 18:08:38 up 115 days,  8:44,  4 users,  load average: 0.03, 0.03, 0.00
Tasks: 325 total,   2 running, 323 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.1%us,  6.4%sy,  0.0%ni, 93.3%id,  0.3%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:  49432728k total,  2063848k used, 47368880k free,   310072k buffers
Swap:  2097144k total,        0k used,  2097144k free,  1297572k cached
PID to renice: 1308 [Hit Enter]
  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
 5359 root      39  19     0    0    0 R 100.1  0.0   9431:35 kipmi0
 1308 deepak  16   0 29492 2292 1512 S  0.7  0.0   0:00.33 top
 6116 root      15   0  369m  30m  11m S  0.7  0.1  77:24.97 cimserver
Give the PID whose nice value has to be changed and hit "Enter". Then give the nice value for the PID
top - 18:08:38 up 115 days,  8:44,  4 users,  load average: 0.03, 0.03, 0.00
Tasks: 325 total,   2 running, 323 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.1%us,  6.4%sy,  0.0%ni, 93.3%id,  0.3%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:  49432728k total,  2063848k used, 47368880k free,   310072k buffers
Swap:  2097144k total,        0k used,  2097144k free,  1297572k cached
Renice PID 1308 to value: -1 [Hit Enter]
  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
 5359 root      39  19     0    0    0 R 100.1  0.0   9431:35 kipmi0
 1308 deepak  16   0 29492 2292 1512 S  0.7  0.0   0:00.33 top
 6116 root      15   0  369m  30m  11m S  0.7  0.1  77:24.97 cimserver
Verify the changes
top - 18:09:06 up 115 days,  8:45,  4 users,  load average: 0.13, 0.06, 0.01
Tasks: 325 total,   1 running, 324 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.0%us,  0.1%sy,  0.0%ni, 99.8%id,  0.1%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:  49432728k total,  2063276k used, 47369452k free,   310072k buffers
Swap:  2097144k total,        0k used,  2097144k free,  1297588k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
 1308 deepak  15  -1 29492 2292 1512 S  0.7  0.0   0:00.42 top
 5359 root      34  19     0    0    0 S  0.7  0.0   9431:42 kipmi0
    1 root      15   0 10352  692  580 S  0.0  0.0   0:02.16 init
    2 root      RT  -5     0    0    0 S  0.0  0.0   0:02.37 migration/0
    3 root      34  19     0    0    0 S  0.0  0.0   0:00.00 ksoftirqd/

5. Kill any task

Press "k" on the terminal when top is running. You should get a prompt as shown below in blue color

top - 18:09:31 up 115 days,  8:45,  4 users,  load average: 0.08, 0.05, 0.01
Tasks: 325 total,   1 running, 324 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.1%us,  0.1%sy,  0.0%ni, 99.8%id,  0.1%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:  49432728k total,  2062036k used, 47370692k free,   310072k buffers
Swap:  2097144k total,        0k used,  2097144k free,  1297596k cached
PID to kill:1308
  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
 5359 root      34  19     0    0    0 S  1.3  0.0   9431:42 kipmi0
 6460 root      24   0  179m  30m 3976 S  1.0  0.1  79:04.77 java
 1308 deepak  15  -1 29492 2292 1512 S  0.7  0.0   0:00.49 top
 1434 root      15   0 29492 2288 1516 R  0.7  0.0   0:00.13 top
top - 18:09:31 up 115 days,  8:45,  4 users,  load average: 0.08, 0.05, 0.01
Tasks: 325 total,   1 running, 324 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.1%us,  0.1%sy,  0.0%ni, 99.8%id,  0.1%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:  49432728k total,  2062036k used, 47370692k free,   310072k buffers
Swap:  2097144k total,        0k used,  2097144k free,  1297596k cached
Kill PID 1308 with signal [15]: [Hit Enter for default]
  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
 5359 root      34  19     0    0    0 S  1.3  0.0   9431:42 kipmi0
 6460 root      24   0  179m  30m 3976 S  1.0  0.1  79:04.77 java
 1308 deepak  15  -1 29492 2292 1512 S  0.7  0.0   0:00.49 top

6. View all the processes running by a user

Press "u" on the terminal when top is running. You should get a prompt as shown below in blue color

top - 18:12:24 up 115 days,  8:48,  4 users,  load average: 0.06, 0.05, 0.00
Tasks: 328 total,   1 running, 327 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.0%us,  0.4%sy,  0.0%ni, 99.6%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:  49432728k total,  2063268k used, 47369460k free,   310072k buffers
Swap:  2097144k total,        0k used,  2097144k free,  1297660k cached
Which user (blank for all): deepak [Hit Enter]
  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
 1729 root      15   0 29488 2196 1432 R  2.0  0.0   0:00.01 top
    1 root      15   0 10352  692  580 S  0.0  0.0   0:02.16 init
    2 root      RT  -5     0    0    0 S  0.0  0.0   0:02.37 migration/0
    3 root      34  19     0    0    0 S  0.0  0.0   0:00.00 ksoftirqd/0
    4 root      RT  -5     0    0    0 S  0.0  0.0   0:00.00 watchdog/0
top - 18:12:41 up 115 days,  8:48,  4 users,  load average: 0.04, 0.05, 0.00
Tasks: 328 total,   1 running, 327 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.0%us,  0.1%sy,  0.0%ni, 99.9%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:  49432728k total,  2062356k used, 47370372k free,   310072k buffers
Swap:  2097144k total,        0k used,  2097144k free,  1297672k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
 1561 deepak  17   0  3984  780  468 S  0.0  0.0   0:00.00 man
 1564 deepak  19   0  8704  964  816 S  0.0  0.0   0:00.00 sh
 1566 deepak  23   0  8704  464  316 S  0.0  0.0   0:00.00 sh
 1571 deepak  16   0  8452  892  712 S  0.0  0.0   0:00.01 less
31328 deepak  15   0  110m 2348 1264 S  0.0  0.0   0:00.20 sshd
31329 deepak  16   0 27676 2564 1816 S  0.0  0.0   0:00.02 bash
31422 deepak  15   0  109m 2360 1260 S  0.0  0.0   0:00.14 sshd
31423 deepak  15   0 27548 2500 1784 S  0.0  0.0   0:00.02 bash

7. Change delay between terminal refresh

By default the top terminal is set for auto refresh after every 3 seconds but if you want you can change it as per your requirement
Press "d" when top is running. You should get a prompt as shown below in blue color
top - 18:14:55 up 115 days,  8:50,  4 users,  load average: 0.01, 0.04, 0.00
Tasks: 328 total,   1 running, 327 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.0%us,  0.1%sy,  0.0%ni, 99.9%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:  49432728k total,  2063828k used, 47368900k free,   310072k buffers
Swap:  2097144k total,        0k used,  2097144k free,  1297728k cached
Change delay from 3.0 to: 2.0 [Hit Enter]
  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
 5359 root      34  19     0    0    0 S  0.7  0.0   9431:58 kipmi0
 1795 root      15   0 29492 2300 1524 R  0.3  0.0   0:00.20 top
    1 root      15   0 10352  692  580 S  0.0  0.0   0:02.16 init
Verify the changes. You must see the screen buffer getting refresh much earlier or just to verify you can provide a higher value of delay and observer the refresh rate on the terminal

8. No. of task to be displayed

By default this option is set to unlimited that is the reason your terminal is fully covered with list of tasks when you run the top command. Any how you can list the no of tasks to be visible once you run top command

Press "n"when top is running. You should get a prompt as shown below in blue color
top - 18:18:07 up 115 days,  8:54,  4 users,  load average: 0.01, 0.03, 0.00
Tasks: 328 total,   1 running, 327 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.0%us,  0.2%sy,  0.0%ni, 99.7%id,  0.1%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:  49432728k total,  2063348k used, 47369380k free,   310072k buffers
Swap:  2097144k total,        0k used,  2097144k free,  1297804k cached
Maximum tasks = 0, change to (0 is unlimited): 2 [Hit Enter]
  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
 5359 root      34  19     0    0    0 S  2.3  0.0   9432:08 kipmi0
 1795 root      15   0 29492 2304 1528 R  0.7  0.0   0:00.65 top
    1 root      15   0 10352  692  580 S  0.0  0.0   0:02.16 init
    2 root      RT  -5     0    0    0 S  0.0  0.0   0:02.37 migration/0

top - 14:48:40 up 116 days,  5:24,  3 users,  load average: 0.05, 0.04, 0.00
Tasks: 318 total,   1 running, 317 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.0%us,  0.1%sy,  0.0%ni, 99.9%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:  49432728k total,  2051952k used, 47380776k free,   310176k buffers
Swap:  2097144k total,        0k used,  2097144k free,  1293800k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
 5359 root      34  19     0    0    0 S  1.0  0.0   9502:15 kipmi0
25009 prasadee  15   0 29492 2280 1516 R  0.3  0.0   0:01.88 top

9. View live individual CPU processor performance

By default top command shows you the average of all the available CPUs in the machine.

In case you want to see report of all the individual CPUs press "1" once you are running top command and you will get to see something like below
top - 00:00:58 up 215 days, 13:36,  5 users,  load average: 4.07, 4.04, 4.00
Tasks: 339 total,   5 running, 334 sleeping,   0 stopped,   0 zombie
Cpu0  :  0.0%us,  0.2%sy,  0.0%ni, 99.8%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Cpu1  :  0.0%us,  0.4%sy,  0.0%ni, 99.6%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Cpu2  :  0.0%us,  0.1%sy,  0.0%ni, 99.5%id,  0.4%wa,  0.0%hi,  0.0%si,  0.0%st
Cpu3  :  0.1%us,  0.2%sy,  0.0%ni, 99.8%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Cpu4  :  0.5%us,  0.1%sy,  0.0%ni, 99.4%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Cpu5  :  0.2%us,  0.4%sy,  0.0%ni, 99.4%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Cpu6  :  0.0%us,  0.5%sy,  0.0%ni, 99.5%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Cpu7  :  0.1%us,  1.4%sy,  0.0%ni, 98.5%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:  49432728k total, 11891852k used, 37540876k free,  7996596k buffers
Swap:  2097144k total,        0k used,  2097144k free,  1850540k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
23102 root      25   0 23724 2024 1168 R 100.1  0.0  64446:36 pvs
23338 root      25   0 23724 2028 1168 R 100.1  0.0  64444:22 pvs
23959 root      25   0 23724 2016 1168 R 100.1  0.0 135691:00 pvs
28698 root      25   0 23724 2024 1168 R 99.3  0.0 128828:38 pvs
 5359 root      34  19     0    0    0 S  0.8  0.0  17610:33 kipmi0

10. Add a new field in top output

By default you see limited set of output when you use the top command. But apart from those there are a other list of field which can be added to the top output. To view all the list f field which can be added follow the below steps.

  • Run top command
  • Press "f" which will take you the list of available fields under top command
  • All the field initials stated in BLOCK letters are visible by default when you issue top command. To add a new field press the field initial as shown in the first column. 
* A: PID        = Process Id                               0x00000001  PF_ALIGNWARN
* E: USER       = User Name                                0x00000002  PF_STARTING
* H: PR         = Priority                                 0x00000004  PF_EXITING
* I: NI         = Nice value                               0x00000040  PF_FORKNOEXEC
* O: VIRT       = Virtual Image (kb)                  0x00000100  PF_SUPERPRIV
* Q: RES        = Resident size (kb)                  0x00000200  PF_DUMPCORE
* T: SHR        = Shared Mem size (kb)                0x00000400  PF_SIGNALED
* W: S          = Process Status                      0x00000800  PF_MEMALLOC
* K: %CPU       = CPU usage                           0x00002000  PF_FREE_PAGES (2.5)
* N: %MEM       = Memory usage (RES)                  0x00008000  debug flag (2.5)
* M: TIME+      = CPU Time, hundredths                0x00024000  special threads (2.5)
  b: PPID       = Parent Process Pid                  0x001D0000  special states (2.5)
  c: RUSER      = Real user name                      0x00100000  PF_USEDFPU (thru 2.4)
  d: UID        = User Id
  f: GROUP      = Group Name
  g: TTY        = Controlling Tty
  j: P          = Last used cpu (SMP)
* P: SWAP       = Swapped size (kb)
  l: TIME       = CPU Time
  r: CODE       = Code size (kb)
  s: DATA       = Data+Stack size (kb)
  u: nFLT       = Page Fault count
  v: nDRT       = Dirty Pages count
  y: WCHAN      = Sleeping in Function
  z: Flags      = Task Flags <sched.h>
* X: COMMAND    = Command name/line
  • For example to add "swap" field press "p" (in small letters). As soon as you press "p" it should turn into block letter notifying that it has been added to top output.
  • Once done hit enter and it will take you back to top output
You should see something like below screen
  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  SWAP COMMAND
20472 prasadee  15   0 30748 2412 1620 R  0.8  0.0   0:00.43  27m top
22568 root      17   0  296m 5300 3536 S  0.4  0.1   3:00.30 291m eventlogd
    1 root      15   0 10348  644  544 S  0.0  0.0   2:28.66 9704 init
    2 root      RT  -5     0    0    0 S  0.0  0.0   0:38.59    0 migration/0
    3 root      34  19     0    0    0 S  0.0  0.0   0:00.43    0 ksoftirqd/0
    4 root      RT  -5     0    0    0 S  0.0  0.0   0:00.00    0 watchdog/0
    5 root      RT  -5     0    0    0 S  0.0  0.0   0:28.64    0 migration/1
    6 root      34  19     0    0    0 S  0.0  0.0   0:00.67    0 ksoftirqd/1
    7 root      RT  -5     0    0    0 S  0.0  0.0   0:00.00    0 watchdog/1
    8 root      RT  -5     0    0    0 S  0.0  0.0   0:28.00    0 migration/2
    9 root      34  19     0    0    0 S  0.0  0.0   0:00.73    0 ksoftirqd/2

I hope the article was useful.

References:
top man page for Linux

6 thoughts on “10 examples to help you understand top command usage in Unix/Linux”

  1. If server has multiple processor suppose (3) is CPU usage will show 300% in top command or consolidate under 100%, and How can we see individual CPU Usage if server has multiple processors

    Reply
  2. If server has multiple processor suppose (3), is CPU usage will show 300% in top command or consolidate under 100%, and How can we see individual CPU Usage if server has multiple processors

    tecgeeks.in

    Reply

Leave a Comment