views:

103

answers:

1

OK so for a programming assignment that I have (Yes, we are all allowed to turn to any source we find suitable for help) I have to find out how much time processes spend blocking/sleeping/running.

My first attempt was creating a bash script... that looked something like this:

for i in `ls /proc/ | egrep [0-9]+`
do
        cat /proc/$i/status | grep State
done

but then all of the problems are reporting the sleeping state. Plus this method would require me to poll like crazy... So running the test will probably change the results... (ugh)

Now compiling a new version of a linux with syscalls or a way to keep tracking of processes states isn't out of the question. My only worry is trying to find out how to keep track of changing process states and making sure that I don't miss anything...

OK, any ideas? Thank you!

+1  A: 

You can use 'time'

 $ time ls /usr/bin

 real    0m4.756s
 user    0m0.051s
 sys     0m0.078s

real - sys = total time waited for I/O (sleeping/blocking)

sys - user = the time spent on system calls

user = the time that was spent by executing the instructions in your program only ( maybe including dynamic linking overhead, not sure about that)

hayalci