From owner-freebsd-newbies Thu Feb 17 16:11:41 2000 Delivered-To: freebsd-newbies@freebsd.org Received: from hydrant.intranova.net (hydrant.intranova.net [209.201.95.10]) by hub.freebsd.org (Postfix) with SMTP id 3CFEA37B822 for ; Thu, 17 Feb 2000 16:11:34 -0800 (PST) (envelope-from oogali@intranova.net) Received: (qmail 96237 invoked from network); 18 Feb 2000 00:03:45 -0000 Received: from localhost (oogali@127.0.0.1) by hydrant.intranova.net with SMTP; 18 Feb 2000 00:03:45 -0000 Date: Thu, 17 Feb 2000 19:03:45 -0500 (EST) From: Omachonu Ogali To: freebsd-newbies@freebsd.org, freebsd-questions@freebsd.org Subject: CPU Information Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-newbies@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org 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 */ #include #include #include #include #include #include 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