To get a live view of the input and output, or short I/O, bandwidth usage of your system, type iotop. iotop needs to be started with the root user. You can use iotop, for example, to learn how fast your hard disk can read and write, then press the q key to exit. Please read the manual section on iotop to learn more about its shortcuts, for example, for sorting columns.
iotop doesn’t come preinstalled with most Linux distributions, you will have to install it using your package manager. For example, in a CentOS/RHEL based system install the iotop package using below command:
# yum install iotop
Simply use below command to run the iotop utility:
# iotop
It displays an output like the following example:
Total DISK READ : 0.00 B/s | Total DISK WRITE : 88.95 M/s Actual DISK READ: 0.00 B/s | Actual DISK WRITE: 88.95 M/s TID PRIO USER DISK READ DISK WRITE SWAPIN IO> COMMAND 27236 be/4 root 0.00 B/s 88.95 M/s 0.00 % 87.91% dd if=/dev/zero of=test.zero bs=1024k count=1000 oflag=direct conv=notrunc 25600 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % less -s 1 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % systemd --switched-root --system --deserialize 22 2 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [kthreadd] 3 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [ksoftirqd/0] 6 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [kworker/u30:0] 7 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [rcu_sched]
Of the columns presented here, we may be interested in the following:
- TID: This column provides the PID of the process that makes I/O requests. This can be used to investigate or terminate the program.
- DISK READ: This column illustrates the number of bytes read per second by the listed process.
- DISK WRITE: This column details the number of bytes written per second by the listed process.
- IO: This column shows the percentage of time that the listed process spent issuing I/O requests.
- COMMAND: This column depicts the name of the process that handles I/O. If this is a master process, it might include command-line switches as well.
Running iotop without any arguments will result in a list of all existing processes regardless of their disk I/O activities, so if you want iotop to only report on processes that are committed to disk I/O activity, you should use the following instead:
# iotop –o
iotop Command Examples
1. For continuous monitoring, use the command as follows:
# iotop -o
The -o option tells iotop to show only those processes that are doing active I/O while running, reducing the noise in the output.
2. The -n option tells iotop to run for N times and exit:
# iotop -b -n 2
3. The -p option monitors a specific process:
# iotop -p PID
Here, PID is the process you wish to monitor.
4. In most modern distributions, instead of finding the PID and supplying it to iotop, you can use the pidof command and write the preceding command as follows:
# iotop -p `pidof cp`
5. Together with the -o flag, these flags can be used to tell iotop to print only the processes using I/O without clearing the screen for the next iteration:
# iotop -o -q -n2
By default, the delay between iotop iterations is 1 second; however, this can be modified with the -d (delay) flag.
6. You can learn more about iotop by reviewing the manual like this:
$ man iotop
Summary
Every administrator knows that a system can begin to slow down as a result of heavy disk I/O activities. However, in the role of a troubleshooter, you will probably want to know which processes or (in the case of multi-user systems) which users are the culprits that and it is for this reason, you will want to turn to iotop. This tool shows a list of the most I/O intensive processes in real-time in a top-like interface.