4
votes

I am currently working on a project in Android. I want to get the total cpu usage of each and every process. So i am using the contents of "/proc/pid/stat". I referred this answer to get the stats. Now i got all the utime, stime etc., The problem is with the value of "Hertz". The answer says that it is the number of clock ticks per second. I don't get the exact meaning of clock tick even after browsing a lot. What is a clock tick and is it the frequency of the processor? And the answer says that we can get the clock ticks using

sysconf(_SC_CLK_TCK)

I don't know how to use this linux command in Android to get the clock ticks. I have googled it and i couldn't find it. Pls help me with this. And it would be more helpful if there is an example for this clock tick.

1
Is it true that in a linux system, ticks occur approximately 100 times per second? i.e., 100 clock ticks per second is usual? - Pragatheeswaran
It depnds on the Hertez set in kernel confiiguration. - Dilip Kumar
This might help you to understand better makelinux.net/books/lkd2/ch10lev1sec2 - Dilip Kumar

1 Answers

6
votes

100 is the default value set on Linux. And it appears to be unchanged in Android as shown in the sysconf.c source file - goo.gl/C5yubg

If you see line 167, this is what sysconf(_SC_CLK_TCK) will retrun:

case _SC_CLK_TCK: return SYSTEM_CLK_TCK;

The default value for SYSTEM_CLK_TCK is defined as 100