Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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

share|improve this answer
I'm using centOS and pidstat doesn't seem to come with sysstat. – Sunil Mar 27 '12 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? – BorrajaX Mar 27 '12 at 15:02
I'm using centOS5 and yum whatprovides */pidstat outputs No mathes Found – Sunil Mar 27 '12 at 15:54
I'm afraid I have nothing, then... sorry about that – BorrajaX Mar 27 '12 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}'
share|improve this answer

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.

share|improve this answer

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.

share|improve this answer
Additionally there is /proc/$PID/io. – scai Jul 26 '12 at 6:06

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.