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

  • 4
    You need root, period.
    – psusi
    Dec 19 '14 at 15:30

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.
  • It requires root privileges to run on ubuntu 14.04, but still nice tool to know about
    – ren
    Dec 19 '14 at 15:27
  • Just to make sure, you did try it with sudo, right?
    – Citylight
    Dec 19 '14 at 15:40
  • yeap, it works with sudo. I guess there is no way to achieve my goal without it
    – ren
    Dec 19 '14 at 15:41
  • May be you can let your user run iotop alone with sudo.
    – Citylight
    Dec 19 '14 at 15:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.