Linux: Monitor Processes by “top”

By Xah Lee. Date: . Last updated: .

Linux top is a command line program that lets you monitor CPU usage.

linux top screenshot 2015-12-26
top

In terminal, type top. Then, try the following in order:

  1. z】 → toggle color.
  2. x】 → toggle coloring of sort column.
  3. s 9 9 Enter ↵】 → set update frequency to every 99 seconds.
  4. Space】 → force a update.
  5. >】 → change the sort column to the right of current sort column.
  6. <】 → change the sort column to the left.
  7. R】 → toggel reverse sort order.
  8. O k Enter ↵】 → order by CPU usage. (also 【P】)
  9. O n Enter ↵】 → order by memory usage. (also 【M】)
  10. O a Enter ↵】 → order by pid.
  11. O x Enter ↵】 → order by process name.
  12. c】 → show full path of commands.
  13. k】 → kill a process by pid.
  14. u user】 → show only processes of a user.
  15. h】 → help.
  16. q】 → quit.

Summary Area

top - 12:59:21 up 20:59,  0 users,  load average: 1.05, 0.93, 0.90
      current     system                     past 1 min, 5 min, 15 min
      time        uptime

In general, “load average”/“number of cpu core” = CPU load. Higher than 1 means overloaded.

Tasks: 139 total,   1 running, 137 sleeping,   0 stopped,   1 zombie
Cpu(s):  5.4%us, 32.4%sy,  0.0%ni, 62.2%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
          user    system    niced     idle   IO wait
Mem:    800340k total,   652680k used,   147660k free,    45688k buffers
Swap:   818172k total,     8584k used,   809588k free,   315372k cached

Actual free memory (RAM) available to programs is: free + buffers + cached. For detail, see: Linux: Show Free Memory.

Better is to see memory usage visually. Use htop. 〔►see Linux: Monitor Processes, “htop”

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND

For some explanation of these, do man top.

Common Top Options

Better top: htop

unix “top” is a very old program. It has some problems. For example, sometimes you want to view one particular process, but if you don't have a long screen, it's very diffucult or impossible, unless you find the pid first than call top -p pid.

A much better one is “htop”. See Linux: Monitor Processes, “htop”.