开发者

Obtaining CPU descriptions on Mac OS X

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

On Linux you can do grep "^model name" /proc/cpuinfo and on Windo开发者_JAVA技巧ws 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?


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

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


Have a look at Link. There's a file in the downloaded source called processor_info.c (and a ton of other good stuff) that I'm pretty sure will give you this information.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜