0

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.

user3822453
  • 55
  • 1
  • 5

1 Answers1

1

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/

Coldsteel48
  • 3,482
  • 4
  • 26
  • 43
  • 1
    FYI, the OP called out linux in the last sentence. It wasn't definitive, but it's a good guess. – Lynn Crumbling Nov 11 '14 at 20:58
  • @LynnCrumbling Yes you are right , but osx has some"linux commands" as well , also I am 80% sure it will work under linux machine as well , since it uses the GNU library – Coldsteel48 Nov 11 '14 at 20:59
  • 1
    I thought the question was asking for the processor vendor name, not the L3 cache size. And I'll note that `*sizeof(char)` is never necessary, because `sizeof(char)` is 1 by definition. Always. – Fred Larson Nov 11 '14 at 21:01
  • @Fred Larson , yes you are right :-) fhanged the answer accordingly – Coldsteel48 Nov 12 '14 at 11:29