Determining the amount of time processes spend Blocking/Executing
Asked Answered
Z

2

6

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...

Zeba answered 21/4, 2009 at 14:54 Comment(0)
A
0

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)

Acerbic answered 2/5, 2009 at 0:47 Comment(0)
T
0

If you wanted to get current stats for things currently existing...

ps -Ae pid,comm,state,time,etime

-A for all process, -e for custom output (just pid, command, state, time (CPU time), elapsed time)

Assuming the question is dealing with ALL processes (including finished ones), that would require some sort of auditing daemon to watch over processes and snag that info on completion.

Terrilyn answered 27/11, 2018 at 20:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.