what is the right way to get processor vendor name in c?

1.8k views Asked by At

I would like to check if my processor is AMD or INTEL in C and do necessary action according to that. What is the right and efficient way to get it in C?

Should i run system(linux command) or is there any other nice way to get it.

1

There are 1 answers

4
Coldsteel48 On

Since You didn't point an OS you are working at here is how you do it for OSX

#import <sys/sysctl.h>

I think that in c it is the same library just called by #include To use uint64_t type value you should include <stdint.h>

#include <sys/sysctl.h>

len=0;
uint64_t freq = 0; //

size_t size = sizeof(freq);
sysctlbyname("machdep.cpu.brand_string", NULL, &len, NULL, 0);
if(len) 
{
    sysctlbyname("machdep.cpu.brand_string", &freq, &len, NULL, 0);
}

The answer you will get will be stored in freq

To know the name of sysctlbyname you can run sysctl -a in terminal

I think that sysctl is also compatible with linux but I never test it on linux machine

http://www.unix.com/man-page/freebsd/3/sysctlbyname/