views:

75

answers:

1

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?

+1  A: 

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).

MarkR
I did read that 100 is always presented to userspace... but wasn't sure /proc counted as userspace :)
Brian Makin
I'm not certain I understand: does this mean that HZ is not actually the number that the questioner wanted?
Eric Seppanen
HZ is the number I wanted... but it is a compiled in constant. As long as I'm running on the same machine I compiled for... all is good. But if I move to another machine without recompiling then it might have the wrong value.
Brian Makin