Date: Thu, 17 Feb 2000 19:03:45 -0500 (EST) From: Omachonu Ogali <oogali@intranova.net> To: freebsd-newbies@freebsd.org, freebsd-questions@freebsd.org Subject: CPU Information Message-ID: <Pine.BSF.4.10.10002171902350.96234-100000@hydrant.intranova.net>
next in thread | raw e-mail | index | archive | help
Here's a simple app to display the CPU information on a FreeBSD machine.
I hope it helps anyone...
--- snip ---
/*
* FreeBSD CPU Information 0.1
* ---------------------------
* Simple program to display the total RAM, and CPU information.
* Compile: cc -o cpuinfo cpuinfo.c
* ---------------------------
* Omachonu Ogali <oogali@intranova.net>
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/sysctl.h>
extern int errno;
int main(void)
{
int len, numcpu, cpuspeed, totalmem, usermem;
char cpuarch[64], cpumodel[64];
printf("FreeBSD CPU Information\n");
printf("Version 0.1\n");
printf("http://tribune.intranova.net\n\n");
len = sizeof(cpuarch);
if (sysctlbyname("hw.machine_arch", &cpuarch, &len, NULL, NULL) == -1) {
perror("sysctlbyname()");
return -1;
}
len = sizeof(cpumodel);
if (sysctlbyname("hw.model", &cpumodel, &len, NULL, NULL) == -1) {
perror("sysctlbyname()");
return -1;
}
len = sizeof(cpuspeed);
if (sysctlbyname("machdep.tsc_freq", &cpuspeed, &len, NULL, NULL) == -1) {
perror("sysctlbyname()");
return -1;
}
len = sizeof(numcpu);
if (sysctlbyname("hw.ncpu", &numcpu, &len, NULL, NULL) == -1) {
perror("sysctlbyname()");
return -1;
}
len = sizeof(totalmem);
if (sysctlbyname("hw.physmem", &totalmem, &len, NULL, NULL) == -1) {
perror("sysctlbyname()");
return -1;
}
len = sizeof(usermem);
if (sysctlbyname("hw.usermem", &usermem, &len, NULL, NULL) == -1) {
perror("sysctlbyname()");
return -1;
}
cpuspeed = cpuspeed / 1000000;
totalmem = (totalmem - 1000000) / 1000000;
usermem = (usermem - 1000000) / 1000000;
printf("Architecture:\t%s\n", cpuarch);
printf("Number of CPUs:\t%d\n", numcpu);
printf("CPU Model:\t%s\n", cpumodel);
printf("CPU Speed:\t%dMHz\n", cpuspeed);
printf("Total Memory:\t%dMB\n", totalmem);
printf("User Memory:\t%dMB\n", usermem);
printf("\n");
return 0;
}
--- snip ---
--
+-------------------------------------------------------------------------+
| Omachonu Ogali oogali@intranova.net |
| Intranova Networking Group http://tribune.intranova.net |
| PGP Key ID: 0xBFE60839 |
| PGP Fingerprint: C8 51 14 FD 2A 87 53 D1 E3 AA 12 12 01 93 BD 34 |
+-------------------------------------------------------------------------+
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-newbies" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.10.10002171902350.96234-100000>
