Overview:

  • Command “top” is one of the basic commands used for Linux system / performance monitoring.
  • It tells us many interesting things but we need to understand what is what.

Command line options:

  • -b = batch mode = takes snapshot of immediate status and ends – can be used in pipe or redirect into file
  • -c = show full commands
  • -d = delay between page refresh (-d seconds.tenths)
  • -u / -U = show only processes of given UID or user name
  • -pXXXXX = show only PID(s) = -pXXX1 -pXXX2 or -pXXX1, XXX2
  • -M = shows memory in human readable units (M, G,…)

Typical top output:


top - 11:25:41 up 78 days, 19:13,  6 users,  load average: 12.72, 14.00, 13.90
Tasks: 445 total,   1 running, 444 sleeping,   0 stopped,   0 zombie
Cpu(s): 76.0%us,  0.3%sy,  0.0%ni, 23.7%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:  49454004k total, 44555696k used,  4898308k free,   100656k buffers
Swap: 10241396k total,  3660548k used,  6580848k free, 23499516k cached

PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
10261 nexus     18   0 6832m 5.8g 6360 S 1219.8 12.2  13884:09 java -DnexusApp=LRR -Xmx6g -Dlog4j.configuration=file:etc/DexClientLRRLog4j.properties -Dcom.sun.management.config.file=etc/DexClientLR
5951 root      15   0 13024 1424  812 R  0.7  0.0   0:01.42 top -c
31937 root      20   0 31.1g 5.4g 7820 S  0.3 11.4  24:25.28 /usr/java/latest/bin/java -Djava.util.logging.config.file=/package/apache-tomcat/conf/logging.properties -Djava.util.logging.manager=org.
1 root      15   0 10368  568  536 S  0.0  0.0   0:10.22 init [3]
2 root      RT  -5     0    0    0 S  0.0  0.0   0:35.89 [migration/0]
3 root      34  19     0    0    0 S  0.0  0.0   0:02.02 [ksoftirqd/0]
4 root      RT  -5     0    0    0 S  0.0  0.0   0:00.00 [watchdog/0]
5 root      RT  -5     0    0    0 S  0.0  0.0   0:44.96 [migration/1]

Lines:

  1. top:
    • curent time
    • uptime of the server
    • number of logged users
    • average load on the system – last minute, last 5 minutes, last 15 minutes – showes overall load on CPUs ( 1=100% for 1 cpu) – example is taken from machine with 16 CPUs
  2. tasks:
    • total number of active processes
    • number of currently running processes
    • number of processes in sleeping mode
    • number of stopped processes
    • number of zombies – child processes which already ended but wait until parent process reads their exit status
  3. Cpu(s) – cpu usage in % for:
    • us = user processes
    • sy = system processes – high %sy means jobs of kernel and it means that machine most likely servers as file or database server
    • ni = processes with priority upgrade nice
    • id = idle – not used
    • wa = waiting for I/O
    • hi = hardware interrupts – high %hi could indicate problems with some HW device – check /proc/interrupts to see details
    • si = software interrupts – high %si can indicate problems with drivers – best solution is to update kernel
    • st = stolen – only on virtual machine = cpu(s) stolen by the hypervisor for other tasks
  4. Mem – memory usage:
    • total amount – means total memory which kernel can map
    • used
    • free
    • buffers
  5. Swap:
    • total
    • used
    • free
    • cached
  6. Processes (standard columns):
    • PID – process ID
    • USER
    • PR – priority of the process
    • NI – NICE value of the process
    • VIRT – virtual memory size = theroretical size of memory used for process
    • RES – resident memory size = memory really allocated for process but + memory used by shared libraries
    • SHR – shared memory size = memory used by shared libraries maped to this process
    • S – current status of process = S – sleeping, R – running, Z – zombie
    • %CPU
    • %MEM
    • TIME+ – total time of activity of this process
    • COMMAND – ‘c’ switches between short and full command description
  7. Processes – other usefull columns:
    • SWAP – size of swapped part
    • nFLT – count of page faults
    • nDRT – count of dirty pages

Usefull shortcuts:

  • P = sort by %CPU
  • M = sort by %MEM
  • c = show short/ full command line for process
  • q = quit