I need to calculate CPU usage (user mode, system mode, idle time) of a process in Linux.
I am able to calculate usage in user and system mode using utime
and stime
values from /proc/PID/stat
, but I found nothing which is related to idle time.
I know I can get idle time from /proc/stat
but this value is related to machine, not for particular process.
Is it possible to calculate idle time of a process knowing its PID
(reading data from /proc
directory)?
it's too late but, I guessed this command useful:
to use it in bash file:
you could change grep -v "grep\|root" as you wish. this one line command list all processes which not root owner or system users.
I don't know much about it but maybe the following works:
Hope this helps! :D