How to read any process’ /proc/pid/io

diskioproc

I'm trying to monitor disk activity of each process. One way that I found how to do this is to read /proc/pid/io file and compare fields with previous read. That works fine except my monitoring process seem to be able to read only some io files (for example it has no permissions to read apache's). How to read io of others? Also perhaps there is a better way of achieving this goal?

Edit Obviously I could run the process as root, but I'd like to avoid that

Best Answer

Use iotop.

It should be available in your repo for a Redhat/Centos/Fedora machine (if it is not already installed).

It outputs a similar info as top, but instead of the CPU/memory stats, you will get the IO stats (Disk reads, writes and swapin).

The options -p , -u and --only might be of interest to you.

For example, to see the IO activity of the process with ID 5435, use:

iotop -p 5435

From the man page:

   -p PID, --pid=PID
          A list of processes/threads to monitor (all by default).

   -u USER, --user=USER
          A list of users to monitor (all by default)

   -P, --processes
          Only show processes. Normally iotop shows all threads.