Re: Getting processor description from sysctl
Re: Getting processor description from sysctl
- Subject: Re: Getting processor description from sysctl
- From: Terry Lambert <email@hidden>
- Date: Thu, 15 May 2008 13:39:49 -0700
On May 14, 2008, at 11:26 PM, Philip Aker wrote:
On 08-05-14, at 21:41, Mike wrote:
System Profiler provides the processor name, so there must be a
way to get it. For example on the MacBook it reports:
Processor Name: Intel Core 2 Duo
Maybe:
system_profiler -xml SPHardwareDataType
In C, not from a shell script.
[ ... cute TCL thing elided ... ]
Or if you want to avoid Objective C, parsing XML, or using TCL:
#define CMD "/usr/sbin/system_profiler SPHardwareDataType"
#define TAG "Processor Name: "
#define UNK "UNKNOWN"
char *
get_cpu_name(void)
{
static char cpu_name[128] = UNK;
char buf[sizeof(cpu_name)];
char *p;
char *q;
FILE *fp;
/* Cache results for subsequent calls */
if (!strcmp(UNK, cpu_name)) {
if ((fp = popen(CMD, "r")) != NULL) {
while (fgets(buf, sizeof(buf), fp) != NULL) {
if ((p = strstr(buf, TAG)) != NULL) {
p += strlen(TAG);
if ((q = strchr(p, '\n')) !=
NULL)
*q = 0;
strcpy(cpu_name, p);
break;
}
}
fclose(fp);
}
}
return(cpu_name);
}
...obviously, this could also be done associatively, with or without
the TCL, to capture all the information in a single run of
system_profiler so that it could be used as separate name/value pairs,
and you could look up the value for any name.
It's just not that hard to do this sort of thing without resorting to
interfaces that might break each time there's a software update. Now
the original poster has two examples.
-- Terry
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden