在Mac OS X上获取CPU说明 [英] Obtaining CPU descriptions on Mac OS X
问题描述
我想以编程方式获取Mac OS X上的CPU描述,如下所示:
I'd like to programmatically get the CPU descriptions on Mac OS X, which look something like this:
Intel(R) Core(TM)2 CPU 6700 @ 2.66GHz
Intel(R) Xeon(R) CPU X5550 @ 2.67GHz
在Linux上可以执行grep "^model name" /proc/cpuinfo
,而在Windows上可以查看注册表中HKLM\Hardware\Description\System\CentralProcessor\0
中的ProcessorNameString
值,但是如何在OS X上获取该信息?
On Linux you can do grep "^model name" /proc/cpuinfo
and on Windows you can look at the ProcessorNameString
value in HKLM\Hardware\Description\System\CentralProcessor\0
in the registry, but how do you get that information on OS X?
推荐答案
您可以将machdep.cpu.brand_string
传递给sysctl来检索您要查找的字符串.
You can pass machdep.cpu.brand_string
to sysctl to retrieve the string you're looking for.
[ben@imac ~]$ sysctl machdep.cpu.brand_string
machdep.cpu.brand_string: Intel(R) Core(TM) i5-2400S CPU @ 2.50GHz
相同的信息通过sysctl(3)
功能公开.
The same information is exposed through the sysctl(3)
functions.
[ben@imac ~]$ cat sys.c
#include <sys/types.h>
#include <sys/sysctl.h>
#include <stdio.h>
int main(int argc, char *argv[]) {
char buf[100];
size_t buflen = 100;
sysctlbyname("machdep.cpu.brand_string", &buf, &buflen, NULL, 0);
printf("%s\n", buf);
}
[ben@imac ~]$ ./sys
Intel(R) Core(TM) i5-2400S CPU @ 2.50GHz
这篇关于在Mac OS X上获取CPU说明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!