Linux iotop Command

Linux 命令大全Linux Command Encyclopedia


iotop is a Linux system monitoring tool similar to the top command, but it focuses on displaying disk I/O usage. It can monitor 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, which can pinpoint the read/write speed and cumulative I/O amount of each process.


Installing iotop

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

Examples

# 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.


Common Options and Parameters

Option Description
-oor--only Only display processes actually performing I/O operations
-bor--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 (seconds)
-p PID Only monitor processes with the specified PID
-u USER Only monitor processes of the specified user
-Por--processes Only display processes, not threads
-aor--accumulated Display cumulative I/O instead of bandwidth
-kor--kilobytes Use KB/s instead of B/s as the unit
-tor--time Add timestamps to the output
-qor--quiet Reduce header information (automatically enabled in non-interactive mode)

Shortcut Keys in Interactive Mode

In interactive mode, iotop supports the following shortcut key operations:

Shortcut Key Function
Left/Right arrow keys Change sort field
r Reverse sorting
o Only display active I/O processes (equivalent to the -o option)
p Toggle process/thread display mode
a Toggle cumulative/real-time display mode
q Quit iotop
i Change priority filtering (only display processes with higher priority)
Any key Force refresh display

Output Field Explanation

The output of iotop contains multiple fields, and the meaning of each field is as follows:

  1. TID/PID: Thread ID / Process ID
  2. PRIO: I/O priority (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 will start an interactive interface, displaying the I/O activity of all processes, sorted by I/O usage.

Example 2: Display Only Active I/O Processes

sudo iotop -o

Or pressokey after running iotop to only display processes currently performing I/O operations.

Example 3: Monitor Processes of a Specific User

sudo iotop -u apache

Only monitor the I/O activity of the apache user's processes.

Example 4: Non-interactive Mode Output

sudo iotop -b -n 3 -d 2

Run in non-interactive mode, refreshing every 2 seconds, and exit after outputting results 3 times.

Example 5: Monitor a Specific Process

sudo iotop -p 1234

Only monitor the I/O activity of the process with PID 1234.


Practical Application Scenarios

Scenario 1: Identify the Cause of System Slowdown

When the system becomes slow to respond, run:

sudo iotop -o

This can quickly identify which processes are heavily reading/writing the disk, causing a system I/O bottleneck.

Scenario 2: Monitor Database Performance

For database servers such as MySQL:

sudo iotop -u mysql -o

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

Scenario 3: Periodically Record I/O Activity

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

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


Notes

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

Alternative Tools

If iotop is unavailable, consider the following alternatives:

  1. dstat: Comprehensive performance monitoring tool, includes disk I/O statistics
  2. atop: Advanced system monitoring tool, includes process-level I/O statistics
  3. nmon: 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. Through process-level I/O monitoring, it can quickly locate performance bottlenecks. Mastering the use of iotop can effectively diagnose and solve system performance problems related to disk I/O.


Linux 命令大全Linux Command Encyclopedia

Other Extensions