Linux中进程的空闲时间 [英] Idle time of a process in Linux
问题描述
我需要计算Linux中进程的CPU使用率(用户模式,系统模式,空闲时间).
我可以使用/proc/PID/stat
中的utime
和stime
值来计算用户和系统模式下的使用率,但是没有发现任何与空闲时间相关的信息.
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.
我知道我可以从/proc/stat
获得空闲时间,但是该值与计算机有关,而不是与特定进程有关.
I know I can get idle time from /proc/stat
but this value is related to machine, not for particular process.
是否可以计算出知道进程PID
的进程的空闲时间(从/proc
目录中读取数据)?
Is it possible to calculate idle time of a process knowing its PID
(reading data from /proc
directory)?
推荐答案
我对此了解不多,但也许可以进行以下工作:
I don't know much about it but maybe the following works:
1) Get the process start up time. Im sure thats possible
2) Generate time difference (dTime = CurrentTime - TimeProcessStarted)
3) Substract the time the process is running ( dTime - (usageSystemMode + usageUserMode))
希望这会有所帮助! :D
Hope this helps! :D
这篇关于Linux中进程的空闲时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!