0

I am running a linux process which does the following

  1. Reads all the numeric file names from /proc
  2. For each, it reads the utime and stime from /proc/pid/stat

Now the complete loop takes say starts at t0 time and finishes at t1 time. t1-t0 can be of an order of seconds on a slow processor if number of processes are more...

So Is it right to extrapolate utime and stime ? If yes how should I go about?

Or is there any better way? I dont know how top command does it?

I am trying to create something like a top command.

1 Answers1

0

http://colby.id.au/calculating-cpu-usage-from-proc-stat

You want to read it twice, and use the differences.

Also, remember that there are many different places time can go (for example Steal time). Your numbers won't always add up to 100% if you don't account for all of them.

BraveNewCurrency
  • 12,654
  • 2
  • 42
  • 50