views:

723

answers:

4

How can I get the CPU clock speed in C++?

I am running Ubuntu 9.10 if that makes any difference.

+5  A: 

Read the pseudo-file /proc/cpuinfo. See this link for an explanation of the fields it contains.

anon
This is not the current CPU speed however. Or not always.
Zan Lynx
+1  A: 

This information is available in sysfs. In particular, check out scaling_cur_freq and cpuinfo_cur_freq in /sys/devices/system/cpu/cpu*/cpufreq.

David
A: 

When I had a Compaq Athlon64 laptop, its /proc/cpuinfo always reported its maximum speed.

I only got reliable current frequency numbers from the files in /sys/devices/system/cpu/*/cpufreq.

I suppose your mileage may vary.

Zan Lynx
A: 

try executing the command lscpu

Evans