将 jiffies 转换为秒 [英] convert jiffies to seconds

查看:33
本文介绍了将 jiffies 转换为秒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一段用户空间代码,它正在解析/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 转换为秒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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