linux cpu usage

Posted by davidbobo on Stack Overflow See other posts from Stack Overflow or by davidbobo
Published on 2012-09-06T08:54:09Z Indexed on 2012/09/06 9:38 UTC
Read the original article Hit count: 158

Filed under:

I am working on unix. I want to knwo the current cpu usage of a process. I understood that ps give the average of cpu used till the process is up - it is not the current usage.

Is there a way to print only the cpu from the top command without 10 more parameters and headers? I know how to do it with awk - this is not the way i want to do it.

top  -p 20705 -bc -n 1  | tail -n 2 | awk '{ print $9}' | head -n 1

If there is another simple way to do it, not reading /proc/stat...

If there is a simple way doing it from c++, it is also ok.

© Stack Overflow or respective owner

Related posts about linux