Linux中进程的空闲时间 [英] Idle time of a process in Linux

查看:252
本文介绍了Linux中进程的空闲时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要计算Linux中进程的CPU使用率(用户模式,系统模式,空闲时间). 我可以使用/proc/PID/stat中的utimestime值来计算用户和系统模式下的使用率,但是没有发现任何与空闲时间相关的信息.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆