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?


4 Answers 4


How about PidStat?. Have you tried it? You may need the Pid for the process you want to monitor, but that should be fairly easy to get with the ps command and a bit of awk chop-chopping.

It's part of the package sysstat which you can install in .deb based systems by typing apt-get install sysstat

  • I'm using centOS and pidstat doesn't seem to come with sysstat.
    – 0x0
    Commented Mar 27, 2012 at 12:37
  • Mmmm... That's a bit weird... In CentOS 6.2 (Final), I get this with a yum whatprovides */pidstat outputs: Loaded plugins: fastestmirror, refresh-packagekit Loading mirror speeds from cached hostfile * base: mirror.us.leaseweb.net * extras: centos.mirror.nac.net * rpmforge: apt.sw.be * updates: mirror.us.leaseweb.net sysstat-9.0.4-18.el6.x86_64 : The sar and iostat system monitoring commands Repo : base Matched from: Filename : /usr/bin/pidstat perl-IPC-Locker-1.484-1.el6.rf.noarch Repo: rpmforge Filename : /usr/bin/pidstat What CentOS and repositories are you using?
    – Savir
    Commented Mar 27, 2012 at 15:02
  • I'm using centOS5 and yum whatprovides */pidstat outputs No mathes Found
    – 0x0
    Commented Mar 27, 2012 at 15:54
  • I'm afraid I have nothing, then... sorry about that
    – Savir
    Commented Mar 27, 2012 at 17:01

You can try to use prtstat (sudo apt-get install psmisc):

watch -n1 prtstat <PID> | tee mylog.log

it'll dump the process statistics every second. If you're interested in parsing those data, use the raw version (-r).

In example, if you want utime, you can extend above command to:

prtstat -r 30557 | grep -w utime | awk '{print $4}'

You can use audria for this task:

audria -d 1 $(pidof myprocess) | awk -F "," '{print $7, $28, $32}'

This will set the delay to 1 second, monitor myprocess and print the current CPU (field 7), read bytes/s (field 28) and write bytes/s (field 32). The read/write counters here exclude cached bytes, if you want to include them choose fields 26 and 30 instead.

audria is also capable of executing your process to monitor it right from the start if required. You can also choose a shorter interval or specify multiple PIDs to watch.


You could try looking at the contents of /proc/$PID/status periodically; that should give you a fair amount of the information you're looking for.

  • Additionally there is /proc/$PID/io.
    – scai
    Commented Jul 26, 2012 at 6:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .