Table of Contents

top : How to use top commnands in Linux



top -h

$ top -h
  procps-ng version 3.3.10
Usage:
  top -hv | -bcHiOSs -d secs -n max -u|U user -p pid(s) -o field -w [cols]


Starting top

$ top       <- CPU Order
$ top -d 1   <- interval 1sec



-b :Batch-mode operation

$ top -b     <- display all
$ top -b -n 5 -d 1  > temp.txt   <-  interval 1sec , 5 times


man top

NAME
       top - display Linux tasks

SYNOPSIS
       top -hv|-bcHiOSs -d secs -n max -u|U user -p pid -o fld -w [cols]

DESCRIPTION
       The top program provides a dynamic real-time view of a running system.  It can display system summary informa‐
       tion as well as a list of processes or threads currently being managed by the Linux kernel.

1. COMMAND-LINE Options
       The command-line syntax for top consists of:

         -hv|-bcHiOSs -d secs -n max -u|U user -p pid -o fld -w [cols]

       -b  :Batch-mode operation

       -H  :Threads-mode operation
            Instructs top to display individual threads.  Without this command-line option a summation of all threads
            in each process is shown.  Later this can be changed with the `H' interactive command.


   4a. GLOBAL Commands

          q  :Quit

          H  :Threads-mode toggle
              When this toggle is On, individual threads will be displayed for all processes in all visible task win‐
              dows.  Otherwise, top displays a summation of all threads in each process.

       *  d | s  :Change-Delay-Time-interval
              You will be prompted to enter the delay time, in seconds, between display updates.


   4b. SUMMARY AREA Commands
          1  :Single/Separate-Cpu-States toggle
              When  you  see `%Cpu(s):' in the summary area, the `1' toggle is On and all cpu information is gathered
              in a single line.  Otherwise, each cpu is displayed separately as: `%Cpu0, %Cpu1, ...'  up to available
              screen height.

   4c. TASK AREA Commands
       The task area interactive commands are always available in full-screen mode.

       SORTING of task window

          For  compatibility,  this top supports most of the former top sort keys.  Since this is primarily a service
          to former top users, these commands do not appear on any help screen.
                command   sorted-field                  supported
                A         start time (non-display)      No
                M         %MEM                          Yes
                N         PID                           Yes
                P         %CPU                          Yes
                T         TIME+                         Yes


How to Use Top Command

This is very important.

q      : exit
d | s -> 1   :  interval 1sec  (delay)

1      : Single/Separate-Cpu-States toggle
H      : Threads-mode toggle

P  : Sorted with CPU 
M  : Sorted with Memory


Example

1 : cpu

top - 10:47:30 up 232 days, 17:40,  1 user,  load average: 0.04, 0.04, 0.01
Tasks: 136 total,   1 running, 135 sleeping,   0 stopped,   0 zombie
Cpu0  :  0.5%us,  0.3%sy,  0.0%ni, 98.3%id,  0.9%wa,  0.0%hi,  0.0%si,  0.0%st
Cpu1  :  0.2%us,  0.3%sy,  0.0%ni, 98.6%id,  0.9%wa,  0.0%hi,  0.0%si,  0.0%st
Cpu2  :  0.1%us,  0.2%sy,  0.0%ni, 99.7%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Cpu3  :  0.6%us,  0.3%sy,  0.0%ni, 99.0%id,  0.1%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:   3365124k total,  2870028k used,   495096k free,   219084k buffers
Swap:  4096564k total,      224k used,  4096340k free,  2383132k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
 5695 pal       15   0 19764 3228 2324 S    1  0.1   0:00.20 smbd
    1 root      15   0  2060  588  512 S    0  0.0   0:01.51 init
    2 root      RT  -5     0    0    0 S    0  0.0   0:22.28 migration/0
    3 root      38  19     0    0    0 S    0  0.0   0:00.08 ksoftirqd/0
    4 root      RT  -5     0    0    0 S    0  0.0   0:00.00 watchdog/0
    5 root      RT  -5     0    0    0 S    0  0.0   0:13.58 migration/1







Performance