如何在Windows / Linux C上检查CPU名称,型号,速度? [英] How to check CPU name, model, speed on Windows/Linux C?

查看:91
本文介绍了如何在Windows / Linux C上检查CPU名称,型号,速度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获得有关C的一些有关硬件的信息:

I would like to get some infos with C about hardware:


  1. 我有多少CPU

  2. 每个内核有多少个内核

  3. 每个CPU中每个逻辑有多少逻辑内核

  4. CPU名称+型号

  5. CPU速度+频率

  6. CPU体系结构(x86,x64)

  1. how many CPU's I have
  2. how many cores have each of them
  3. how many logical cores have every core in every CPU
  4. CPU name + model
  5. CPU speed + frequency
  6. CPU architecture (x86, x64)

我知道在类似Linux的操作系统上,我可以解析 / proc / cpuinfo ,但是由于它不是普通文件,因此我认为它是不安全的。看到答案,但它没有给我我需要的每条信息。我应该叫 cat / proc / cpuinfo>吗? file.txt ,然后解析 file.txt ?我知道 cpuid.h (我使用GCC),但找不到有关此标头的任何文档(无论如何-使用它是一个好主意吗?)

I know that on Linux-like OS I can parse /proc/cpuinfo but since its not an ordinary file, I think its unsafe. Saw this answer on SO but it doesnt give me EVERY info I need. Should I call cat /proc/cpuinfo > file.txt and then parse file.txt? I know about cpuid.h (Im using GCC) but ca't find any doc about this header (anyway - is it a good idea to use it?)

推荐答案

Linux procfs的伪造文件可能会出现很大问题。内核错误地将它们报告为常规文件,但它们的行为不符合常规POSIX系统上所需的常规文件。例如,请参见 http://www.openwall.com/lists/ musl / 2013/05/05/9 。我怀疑您听说过类似的报道,而这正是您担心的地方。

Linux procfs's fake files can behave very problematically. The kernel falsely reports them as regular files, but they don't behave as regular files are required to on a conforming POSIX system. For an example, see http://www.openwall.com/lists/musl/2013/05/05/9. I suspect you've heard similar reports and this is where your concern is coming from.

据我所知,所有的不良行为 / proc 中的假常规文件仅与写入有关。为了阅读它们,它们的行为应与实际的常规文件足够相似,您可以按自己喜欢的方式阅读它们,而不必担心。

With that said, as far as I know, all of the bad behavior of the fake "regular files" in /proc pertains only to writing. For reading they should behave sufficiently similar to actual regular files that you can just read them however you like and not worry about it.

这篇关于如何在Windows / Linux C上检查CPU名称,型号,速度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆