Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Linux iotop command

Linux iotop command

Linux Command Reference Linux Command Reference


iotop is a Linux system monitoring tool similar to the top command, but it focuses on displaying disk I/O usage. It monitors the disk read/write activity of each process in the system in real time, helping system administrators identify I/O-intensive processes.

Unlike tools such as iostat, iotop provides process-based I/O monitoring, accurate down to the read/write speed and cumulative I/O of each process.


Install iotop

Most Linux distributions do not install iotop by default, so it must be installed manually:

Example

Debian/Ubuntu systems

sudo

apt-get install

iotop

RHEL/CentOS systems

sudo

yum install

iotop

Fedora systems

sudo

dnf

install

iotop

Arch Linux

sudo

pacman

-S

iotop


Basic Syntax

The basic command format of iotop is as follows:

sudo iotop [选项]

Note: iotop requires root privileges to run, because it needs to access the kernel's I/O statistics.


Commonly used options

Option Description
-o or --only Show only processes actually performing I/O
-b or --batch Non-interactive mode, suitable for use in scripts
-n NUM Number of iterations to run in non-interactive mode
-d SEC Set the refresh interval in seconds
-p PID Monitor only the process with the specified PID
-u USER Monitor only processes of the specified user
-P or --processes Show processes only, not threads
-a or --accumulated Show cumulative I/O instead of bandwidth
-k or --kilobytes Use KB/s instead of B/s as the unit
-t or --time Add timestamps to the output
-q or --quiet Reduce header information (enabled automatically in non-interactive mode)

Shortcut keys in interactive mode

In interactive mode, iotop supports the following shortcut keys:

Keyboard shortcut Function
Left and right arrow keys Change the sort field
r Reverse order sorting
o Show only active I/O processes (equivalent to the -o option)
p Toggle between process and thread display modes
a Toggle between cumulative and real-time display modes
q Exit iotop
i Change priority filtering (show only higher-priority processes)
Any key Force a display refresh

Explanation of output fields

The output of iotop contains several fields, each with the following meaning:

  1. TID/PID: Thread ID / process ID
  2. PRIO: I/O priority (the Linux ionice value)
  3. USER: Process owner
  4. DISK READ: Disk read speed
  5. DISK WRITE: Disk write speed
  6. SWAPIN: Swap space usage percentage
  7. IO>: I/O usage percentage
  8. COMMAND: Process name

Usage examples

Example 1: Basic monitoring

sudo iotop

This starts the interactive interface, showing the I/O activity of all processes sorted by I/O usage.

Example 2: Show only active I/O processes

sudo iotop -o

Alternatively, after running iotop, pressoto show only processes currently performing I/O operations.

Example 3: Monitor processes of a specific user

sudo iotop -u apache

Monitor only the I/O activity of processes owned by the user apache.

Example 4: Non-interactive mode output

sudo iotop -b -n 3 -d 2

Run in non-interactive mode, refreshing every 2 seconds, output 3 results, and then exit.

Example 5: Monitor a specific process

sudo iotop -p 1234

Monitor only the I/O activity of the process with PID 1234.


Practical Application Scenarios

Scenario 1: Identify why the system has slowed down

When the system responds slowly, run:

sudo iotop -o

you can quickly find which processes are reading from or writing to disk heavily, causing a system I/O bottleneck.

Scenario 2: Monitor database performance

For database servers such as MySQL:

sudo iotop -u mysql -o

Monitor the I/O activity of the mysql user specifically to analyze the database's disk load.

Scenario 3: Periodically log I/O status

sudo iotop -b -t -n 5 -d 10 > iotop_log.txt

Log the I/O status every 10 seconds, 5 times in total, and save the results to a file for later analysis.


Notes

  1. iotop requires kernel support for the I/O accounting feature, which is usually enabled in newer Linux kernels.
  2. In some virtualized environments, iotop may not report I/O statistics accurately.
  3. Frequent refreshing (such as an interval of less than 1 second) may affect system performance.
  4. Cumulative I/O statistics (the -a option) are reset after a system reboot.
  5. For SSD devices, a high I/O wait time may indicate that the device has reached its performance limit.

Alternative tools

If iotop is unavailable, consider the following alternatives:

  1. dstat: A comprehensive performance monitoring tool that includes disk I/O statistics
  2. atop: An advanced system monitoring tool that includes process-level I/O statistics
  3. nmon: An AIX/Linux performance monitoring tool
  4. pidstat: Part of the sysstat toolkit, can report process I/O

Summary

iotop is a powerful tool for Linux system administrators to monitor disk I/O activity; with process-level I/O monitoring, it can quickly locate performance bottlenecks. Mastering iotop enables you to effectively diagnose and solve system performance problems related to disk I/O.


Linux Command Reference Linux Command Reference