How can I programmatically find the CPU frequency with C

后端 未结 5 1510

I\'m trying to find out if there is anyway to get an idea of the CPU frequency of the system my C code is running on.

To clarify, I\'m looking for an abstract soluti

5条回答
  •  时光说笑
    2020-12-08 08:57

    The CPU frequency is a hardware related thing, so there's no general method that you can apply to get it, it also depend on the OS you are using.

    For example if you are using Linux, you can either read the file /proc/cpuinfo or you can parse the dmesg boot log to get this value or if you want you can see how linux kernel handle this stuff here and try to customize the code to meet your need :

    https://github.com/torvalds/linux/blob/master/arch/x86/kernel/cpu/proc.c

    Regards.

提交回复
热议问题