How to Use the iotop Command in Linux for Disk I/O Monitoring

The iotop command in Linux is an essential tool for monitoring disk I/O activity in real time. If your server or system experiences slow performance, high disk I/O usage from certain processes could be the reason. With iotop, you can track disk read and write operations, identify resource-heavy processes, and optimize performance effectively.

In this guide, we’ll cover how to install and use the iotop command in Linux, explain its output, and explore its most useful options.

For a step-by-step visual demonstration, watch this video:


What is the iotop Command in Linux?

The iotop command in Linux is a system monitoring utility that displays disk I/O usage per process. It helps identify processes consuming excessive disk resources, which is crucial for optimizing system performance.

Why Use the iotop Command in Linux?

✅ Identifies processes consuming high disk I/O
✅ Helps troubleshoot slow performance issues
✅ Monitors real-time read/write disk activity
✅ Assists in optimizing server performance

For example, if your Linux server suddenly slows down, the iotop command in Linux can help you determine which processes are overloading the disk.


Installing the iotop Command in Linux

To install iotop in Linux, run the following command based on your distribution:

For Rocky Linux & RHEL-based distributions:

sudo dnf install iotop

For Debian-based distributions (Ubuntu, Debian):

sudo apt install iotop

Once installed, you can start monitoring disk I/O usage.


How to Use the iotop Command in Linux

Running the Basic iotop Command

To launch iotop in Linux, run:

sudo iotop

Since iotop requires access to system statistics, you must run it with superuser privileges (sudo).

Understanding the Output

A typical iotop command output looks like this:

Total DISK READ: 0.00 B/s | Total DISK WRITE: 1.75 K/s
TID  PRIO  USER     DISK READ  DISK WRITE  SWAPIN    IO>    COMMAND
1234 be/4 root     0.00 B/s   1.00 K/s    0.00 %    0.00 %   /usr/bin/someprocess
2345 be/4 user     0.00 B/s   0.75 K/s    0.00 %    0.00 %   /usr/bin/otherprocess

Key Columns Explained

TID – Thread ID of the process
PRIO – Priority of the process
USER – User running the process
DISK READ – Data read from disk by the process
DISK WRITE – Data written to disk by the process
COMMAND – The command initiating the process


Useful Options for the iotop Command in Linux

The iotop command in Linux includes several useful options to refine its output.

1. Show Only Processes with Active I/O (-o)

To display only active I/O processes, use:

sudo iotop -o

📌 Use case: Useful for diagnosing high disk usage by filtering out inactive processes.

2. Batch Mode (-b) for Logging

To capture iotop output for later analysis, run:

sudo iotop -b -n 10

Save the output to a file:

sudo iotop -b -n 10 > iotop_output.txt

📌 Use case: Useful for performance audits and automated monitoring.

3. Adjust Update Interval (-d)

Modify the update frequency using the -d flag:

sudo iotop -d 5

📌 Use case: Helps reduce noise and focus on trends over time.

4. Display Timestamp (-t)

To include timestamps, run:

sudo iotop -t

📌 Use case: Useful for logging and correlating I/O spikes with system events.

5. Show Only Processes (-P)

To display only processes, excluding threads, use:

sudo iotop -P

📌 Use case: Makes output easier to analyze by focusing on process-level disk usage.


Real-World Use Case: Troubleshooting Slow Performance

Scenario: Diagnosing High Disk I/O on a Linux Server

If your Rocky Linux web server slows down, run:

sudo iotop -o -d 2 -t

✅ Shows only active I/O processes
✅ Updates every 2 seconds
✅ Includes timestamps for better tracking

If a specific process is consuming excessive disk I/O, you can optimize it, restart it, or offload its workload.


Simulating High Disk I/O in Linux

To simulate high disk I/O and observe iotop in action, run:

sudo dd if=/dev/zero of=/tmp/testfile bs=1M count=1000

Now, check disk usage using:

sudo iotop

The dd process will appear with high disk I/O usage. To stop it, press Ctrl + C.


Frequently Asked Questions (FAQs)

1. What is the iotop command used for?

The iotop command in Linux monitors real-time disk I/O activity per process, helping to identify high-resource-consuming processes.

2. Can I use iotop without sudo?

No, iotop requires superuser privileges to access low-level system statistics.

3. How do I log iotop output for analysis?

Use iotop -b -n 10 > iotop_output.txt to save the output to a file.

4. How do I filter only active I/O processes?

Run sudo iotop -o to display only processes currently performing disk I/O.

5. How do I adjust the refresh rate in iotop?

Use iotop -d <seconds>, for example, iotop -d 5, to set the update interval.


Conclusion

The iotop command in Linux is an invaluable tool for monitoring and troubleshooting disk I/O issues. Whether you’re managing a Rocky Linux server or a personal Linux system, iotop helps track real-time disk usage, identify bottlenecks, and optimize performance.

If your Linux system slows down, use iotop to diagnose disk I/O issues and take corrective action.

For a detailed walkthrough, watch this video.


See also:

List of monitoring tools 

Linux Blogs

AWS Cloud Blogs

Database Blogs

DevOps Blogs

Interview Questions & Answers

Docker Blogs

Google Cloud Blogs







Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.