Analyzing the Output of the top Utility
Greetings!

In this theoretical note, we will take a detailed look at the output of the top command - a utility for basic Linux diagnostics.

top is a process manager utility for the Linux command line that provides a dynamic, real-time view of running processes and system resources (CPU, memory).

Every advanced Linux user is strongly recommended to know about top, know how to work with it, and interpret its output.

The metrics displayed in top output are very often asked about in IT interviews☝️.

To call the process manager, simply run:

BASH
top -c
Click to expand and view more

Below is a detailed breakdown of this utility’s output.

Line 1 - Start Time, Users, and Load Average

BASH
top - 14:41:16 up 5:46, 1 user, load average: 0.86, 0.35, 0.13
Click to expand and view more

Breakdown of metrics:

Line 2 - Task Summary (Tasks)

BASH
Tasks: 642 total, 1 running, 641 sleeping, 0 stopped, 0 zombie
Click to expand and view more

Breakdown of metrics:

Line 3 - CPU Statistics

BASH
%Cpu(s): 1.9 us, 2.5 sy, 0.0 ni, 95.5 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
Click to expand and view more

Breakdown of metrics (percentage of time):

Line 4 - Memory (Physical RAM)

BASH
MiB Mem: 48163.6 total, 44135.4 free, 2643.1 used, 1928.9 buff/cache
Click to expand and view more

Breakdown of metrics:

Line 5 - Memory (swap)

BASH
MiB Swap: 2048.0 total, 2048.0 free, 0.0 used
Click to expand and view more

Disk space used to unload inactive memory pages from RAM.

Breakdown of metrics:

Line 6 - Process Table

BASH
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
Click to expand and view more

Column breakdown:

  1. PID (Process ID) - unique process identifier;
  2. USER - effective user identifier (EUID) under which the process is running;
  3. PR (Priority) - dynamic priority of the kernel scheduler (RT - Real Time);
  4. NI (Nice) - “niceness” value (-20 - highest priority, +19 - lowest). Affects PR;
  5. VIRT (Virtual Image) - virtual amount of memory reserved by the process (code + data + shared libraries + pages in swap). Does not show real physical RAM consumption;
  6. RES (Resident Size) - physical memory used by the process that has not been swapped out (code + data). Main RAM consumption metric;
  7. SHR (Shared Mem) - part of RES memory that can be shared with other processes (glibc libraries and others);
  8. TIME+ - total CPU time spent by the process, accurate to hundredths of a second;
  9. COMMAND - process launch command.

Process States (S Column)

This is the most important column for deep diagnostics.

CodeStatus (State)Technical descriptionInterpretation
RRunningRunning or RunnableThe process is either executing on a core or is in the scheduler queue (Run queue).
SSleepingInterruptible SleepWaiting for an event (input completion, timer, signal). Can be interrupted by a signal.
DDisk SleepUninterruptible SleepThe process is waiting for a response from hardware (usually I/O). It cannot be killed (kill -9 will not work) until the driver returns control. Accumulation of D processes raises Load Average.
ZZombieZombieThe process has finished (exit()), memory has been freed, but an entry remains in the process table because the parent has not called wait().
TStoppedStoppedStopped by a job-control signal (SIGSTOP/SIGTSTP) or debugger (ptrace).
tTracingTracing stopStopped by a debugger during tracing.
IIdleIdle (Kernel thread)Kernel thread in idle mode (not counted in Load Average). Usually [kworker] processes.

Useful Keyboard Shortcuts in Interactive top

A useful command for output to a script/log (non-interactive):

BASH
top -b -n 1 
Click to expand and view more

It captures the state of all processes at the time of execution.

There are also popular managers htop - more convenient interactively, and atop, which can save metric history, but that is another story😉.

Read more about process management in a separate article: 🔗 Linux Command Line, Processes: jobs, fg, bg, ps, pgrep, kill, pkill, htop Commands

An Interesting Case from the Chat

Copyright Notice

Author: Иван Чёрный

Link: https://r4ven.me/en/monitoring/razbor-vyvoda-utility-top/

License: CC BY-NC-SA 4.0

Использование материалов блога разрешается при условии: указания авторства/источника, некоммерческого использования и сохранения лицензии.

Start searching

Enter keywords to search articles

↑↓
ESC
⌘K Shortcut