If you need to find out what processes on your desktop or server are doing a lot of disk I/O (reads/writes) or swapping in and out of memory a lot, then take a look at iotop.
Iotop is a top-like program (written in python) for investigating/monitoring process disk and swap space usage. Iotop displays the disk and swap usage information as it happens. You can use iotop to identify which processes on your system are keeping your hard drive busy with reads and/or writes. You can also use it to determine which processes (if any) are swapping in the most or even thrashing swap space.
To install iotop, use:
sudo apt-get install iotop
To start iotop, just run the command:
(Hit q to exit).
You can use iotop in several modes, depending on what your aiming to do. If you want to immediately identify which processes are grinding your hard disk to a halt, hit o to only show processes that are doing IO.
To toggle between showing just processes rather than each thread, hit P.
To only monitor specific processes, start iotop with "-p". For example to monitor processes with id 12345 and 23456, use:
sudo iotop -p 12345 -p 23456
To monitor IO for specific users only, start iotop with "--user" for each user your interested in e.g.
sudo iotop --user root --user jimbob
By default the results are sorted by IO bandwidth used. You can change the field used for sorting by using the left and right arrows. The active sort field will have a ">" or "<" beside it. The sorting order can be changed by hitting r (note the ">" change to "<" or vice versa).
You can change the delay (in seconds) between iterations by starting iotop with "-d". e.g. for a 2 second refresh interval, run:
sudo iotop -d 2
To continually dump the display to screen (or wherever), use batch mode. If you use batch mode, you cannot use the interactive options. To start in batch mode:
sudo iotop -b
(Just use Ctrl+c to exit batch mode). To add a timestamp to each line, use the "-t" command line option, which automatically sets iotop to batch mode.
sudo iotop -t
To save to file (with timestamps)
sudo iotop -f > iotop_sample.txt
See the man page for further information.
Thanks to Guillaume Chazarain for writing iotop.