我有一段用户空间代码,它正在解析/proc/PID/task/TID/stat 以获取 cpu 使用情况.我可以使用 HZ 获得每秒 jiffies,但此代码可以移动到另一台具有不同配置值的机器.有没有办法在运行时从用户空间获取HZ的值?
I've got a piece of userspace code which is parsing /proc/PID/task/TID/stat to get the cpu usage. I can use HZ to get the jiffies per second but this code could move to another machine which has a different configured value. Is there any way to get the value of HZ from userspace at runtime?
推荐答案你把它除以你从 sysconf(_SC_CLK_TCK) 得到的数字.
You divide it by the number you get from sysconf(_SC_CLK_TCK).
然而,我认为在 Linux 下这可能总是 100,不管实际时钟滴答如何,它总是作为 100 呈现给用户空间.
However, I think this is probably always 100 under Linux regardless of the actual clock tick, it's always presented to userspace as 100.
参见 man proc(5).
See man proc(5).
更多推荐
将 jiffies 转换为秒
发布评论