From owner-freebsd-questions Mon Jul 30 12:45:24 2001 Delivered-To: freebsd-questions@freebsd.org Received: from freeze.org (www.stelesys.com [208.177.187.226]) by hub.freebsd.org (Postfix) with ESMTP id 917DE37B405 for ; Mon, 30 Jul 2001 12:44:59 -0700 (PDT) (envelope-from jim@freeze.org) Received: (from jim@localhost) by freeze.org (8.11.3/8.11.2) id f6UJlFH19638; Mon, 30 Jul 2001 15:47:15 -0400 (EDT) (envelope-from jim) X-Authentication-Warning: www.stelesys.com: Processed from queue /var/spool/alt_queue X-Authentication-Warning: www.stelesys.com: Processed by jim with -C /web/siteinfo/freeze/mail/sendmail.cf Date: Mon, 30 Jul 2001 15:47:09 -0400 (EDT) From: Jim Freeze X-X-Sender: To: Marius Cc: Subject: Re: getting cpu info In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Here is a little piece of c code that was previously posted here. Works great. Sample output: % machid FreeBSD CPU Information Version 0.1 http://tribune.intranova.net Architecture: i386 Number of CPUs: 1 CPU Model: AMD-K6(tm) 3D processor CPU Speed: 400MHz Total Memory: 60MB User Memory: 47MB --begin code--- /* * FreeBSD CPU Information 0.1 * --------------------------- * Simple program to display the total RAM, and CPU information. * Compile: cc -o cpuinfo cpuinfo.c * --------------------------- * Omachonu Ogali */ /* Sample Output * Architecture: i386 * Number of CPUs: 1 * CPU Model: Pentium II/Pentium II Xeon/Celeron * CPU Speed: 400MHz * Total Memory: 124MB * User Memory: 104MB */ #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 - 1048576) / 1048576; usermem = (usermem - 1048576) / 1048576; 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; } --end code--- On Mon, 30 Jul 2001, Marius wrote: > > I am trying to audit our company's network of *nix machines to find > candidates for replacement for newer faster models. I basically want > write a script that logs in, executes some commands, and saves the > appropriate info. Perl is certainly up to the task, so that isn't a > problem. I'm just not sure how to grab the appropriate cpu info from our > FreeBSD machines. Linux has `cat /proc/cpuinfo` but I can't think > of anything similar in FreeBSD. > > I am most of the way there, I have everything I need except the speed of > the cpu(s) in MHz. Anybody know a quick and easy way to grab the cpu speed > on a machine without rebooting it? I can do a lot with sysctl > to get memory resources and the number of cpu's, but a listing for > speed has thus far eluded me. > > # sysctl hw.physmem > # sysctl hw.ncpu > > Tell me most of what I want to know, but hw.model is not specific enough > for my purposes. Am I overlooking a sysctl variable, or is there some > other utility I could use? Anyone have a suggestion? > > Obviously this stuff would be in the boot messages of these machines, but > these machines are in production, and I would rather not reboot them. And > because of that 'darned' stability that FreeBSD has, the boot messages > have long ago been wiped out of dmesg.yesterday and dmesg.today. ;) > > Any pointers would be appreciated. Please cc: me, as I am subscribed to > stable, but not questions. > > --------------------------------------------------------------- > -Marius M. Rex > > "Do not try to solve all life's problems at once -- learn to > dread each day as it comes." > -- Donald Kaul > > > > > To Unsubscribe: send mail to majordomo@FreeBSD.org > with "unsubscribe freebsd-questions" in the body of the message > ========================================================= Jim Freeze jim@freeze.org --------------------------------------------------------- No comment at this time. http://www.freeze.org ========================================================= To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message