Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I want to monitor CPU usage, disk read/write usage for a particular process, say ./myprocess.

To monitor CPU top command seems to be a nice option and for read and write iotop seems to be a handy one.

For example to monitor read/write for every second i use the command iotop -tbod1 | grep "myprocess".

My difficulty is I just want only three variables to store, namely read/sec, write/sec, cpu usage/sec. Could you help me with a script that combines the outputs the above said three variables from top and iotop to be stored into a log file?


share|improve this question
add comment

1 Answer

While I realize that you want to monitor a specific process, I still want to point you to the tool "dstat".

dstat combines several tools, such as ifstat, iostat, vmstat and netstat. Although you can't point dstat to a specific PID, you still can have a look at the results and extract the information you need.

Ah, and by the way: nethogs might also be of interest for you. This tool shows you the caused network traffic per process.

share|improve this answer
For some reason dstat gives different CPU usage from top. I'm not sure why. I'm running a basic cpu intensive code (calculate very large fibonacci number) and seeing two different results. –  Sunil Mar 26 '12 at 18:37
dstat reads the values from the /proc file system. With a small delay being recognized, those values should be correct. What results do you see in top, what in dstat? Where exactely is the difference? –  Valentin Mar 26 '12 at 20:10
I understood what was going on. Since I've two cpu cores dstat showed the average while top just showed the percentage of all processes together but not necessarily related to the CPU cores. dstat is useful but as you said I want a way to monitor cpu and io usage of a particular process. –  Sunil Mar 26 '12 at 20:31
Hm, if you know the process ID right after the process started, you could read the content of /proc/<PID>/<file name with stats here>. It should contain both the IO and CPU usage. –  Valentin Mar 26 '12 at 20:49
How can I use that with dstat? Can you given an example using a sample PID? –  Sunil Mar 26 '12 at 21:09
show 2 more comments

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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