gpt4 book ai didi

linux - Linux 进程空闲时间

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:27:41 25 4
gpt4 key购买 nike

我需要计算 Linux 中进程的 CPU 使用率(用户模式、系统模式、空闲时间)。我能够使用 /proc/PID/stat 中的 utimestime 值来计算用户和系统模式下的使用情况,但我什么也没发现与空闲时间有关。

我知道我可以从 /proc/stat 获取空闲时间,但这个值与机器有关,而不是针对特定进程。

是否可以计算一个进程的空闲时间,知道它的 PID(从 /proc 目录读取数据)?

最佳答案

我对此了解不多,但也许以下作品:

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

关于linux - Linux 进程空闲时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9053236/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com