Linux iotop Command
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
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:
- TID/PID: Thread ID / Process ID
- PRIO: I/O priority (Linux ionice value)
- USER: Process owner
- DISK READ: Disk read speed
- DISK WRITE: Disk write speed
- SWAPIN: Swap space usage percentage
- IO>: I/O usage percentage
- 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
- iotop requires the kernel to support the I/O accounting feature, which is usually enabled in newer Linux kernels.
- In some virtualized environments, iotop may not accurately report I/O statistics.
- Frequent refreshing (such as intervals less than 1 second) may affect system performance.
- Cumulative I/O statistics (-a option) will be reset after a system reboot.
- 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:
- dstat: Comprehensive performance monitoring tool, includes disk I/O statistics
- atop: Advanced system monitoring tool, includes process-level I/O statistics
- nmon: AIX/Linux performance monitoring tool
- 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.
Other Extensions
Linux Command Encyclopedia