5
"""Returns the number of jiffies per second for this machine.
7
A jiffy is a value used by the kernel to report certain time-based
8
events. Jiffies occur N times per second where N varies depending
9
on the hardware the kernel is running on. This function gets the
10
uptime for the current process, forks a child process and gets the
11
uptime again; finally, using the running time of the child process
12
compared with the uptimes to determine number of jiffies per
15
uptime1_file = open("/proc/uptime")
16
uptime2_file = open("/proc/uptime")
17
read_uptime1 = uptime1_file.read
18
read_uptime2 = uptime2_file.read
21
uptime1_data = read_uptime1()
23
# Fork a process and exit immediately; this results in the
24
# child process being left around as a zombie until waitpid()
30
uptime2_data = read_uptime2()
32
stat_file = open("/proc/%d/stat" % pid)
33
stat_data = stat_file.read()
38
seconds_uptime1 = float(uptime1_data.split()[0])
39
seconds_uptime2 = float(uptime2_data.split()[0])
40
jiffie_uptime = int(stat_data.split()[21])
42
jiffies1 = int(jiffie_uptime/seconds_uptime1+0.5)
43
jiffies2 = int(jiffie_uptime/seconds_uptime2+0.5)
45
if jiffies1 == jiffies2: