3

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

I am running Ubuntu 9.10 if that makes any difference.

naspinski
  • 34,020
  • 36
  • 111
  • 167

4 Answers4

7

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

  • 3
    This is not the current CPU speed however. Or not always. – Zan Lynx Mar 10 '10 at 17:17
  • There are new links. For RHEL 4, the explanation is in the [Reference Guide](https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/4/html/Reference_Guide/s2-proc-cpuinfo.html). For RHEL 6, the explanation is in the [Deployment Guide](https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Deployment_Guide/s2-proc-cpuinfo.html) – Jaime Sep 16 '17 at 17:01
2

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
  • 2,947
  • 1
  • 25
  • 19
1

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
  • 53,022
  • 10
  • 79
  • 131
1

try executing the command lscpu

BlueSilver
  • 1,052
  • 2
  • 10
  • 25