Sunday, January 28, 2024

[SOLVED] convert jiffies to seconds

Issue

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?


Solution

You divide it by the number you get from sysconf(_SC_CLK_TCK).

However, I think this is probably always 100 under Linux regardless of the actual clock tick, it's always presented to userspace as 100.

See man proc 5.



Answered By - MarkR
Answer Checked By - Clifford M. (WPSolving Volunteer)