2

I can get cpu usage percentage with ps command

ps -ax -o pid,rss,pcpu,command

But there are processes for which it prints 0.0. I know that the reason is because the value is too small. Is there any way (ps option for example) to print these values more precise like 0.002?

Ashot Khachatryan
  • 2,156
  • 2
  • 14
  • 30
  • Look at this thread, it might help you : [http://stackoverflow.com/questions/14041044/memory-usage-with-high-precision] – hkN Apr 30 '15 at 11:01
  • 1
    I'd look towards /proc/pid/stat, [this answer](http://stackoverflow.com/questions/5514119/accurately-calculating-cpu-utilization-in-linux-using-proc-stat) seems relevant – bobah Apr 30 '15 at 11:02

1 Answers1

0

ps or top cannot provide you accurate results on cpu usage. Perhaps you can try OProfile instead that will give you exactly the CPU usage consumed by your process. The following link contains a basic how-to tutorial on OProfile: http://lbrandy.com/blog/2008/11/oprofile-profiling-in-linux-for-fun-and-profit/

ioko
  • 61
  • 5
  • 1
    Actually, the`/proc/pid/stat` provides CPU usage with precision of 10ms of cpu time (depending on USER_HZ). – myaut Apr 30 '15 at 13:49