Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Obtaining CPU descriptions on Mac OS X

Tags:

macos

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 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?

like image 356
markshep Avatar asked Apr 13 '11 14:04

markshep


People also ask

How do I show the CPU in the menu bar Mac?

In the menu, select “Dock Icon,” and you will see several options. For now, select “Show CPU Usage.” With “Show CPU Usage” turned on, Activity Monitor's dock icon will transform into a 10-segment gauge that lights up, depending on how much CPU activity is taking place.

How do I check my CPU and GPU on Mac?

Check if the discrete or integrated GPU is in use To see which graphics cards are in use, choose Apple () menu > About this Mac. The graphics cards currently in use appear next to Graphics. Learn which integrated GPUs your Mac might have.


1 Answers

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
like image 197
Ben Avatar answered Sep 21 '22 03:09

Ben