Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 30 Jul 2001 18:29:06 -0400 (EDT)
From:      Jim Freeze <jim@freeze.org>
To:        Alexander V P <alex@big-blue.net>
Cc:        Marius <marius@mail.communityconnect.com>, <questions@FreeBSD.ORG>
Subject:   Re: getting cpu info 
Message-ID:  <Pine.BSF.4.32.0107301827540.7577-100000@www.stelesys.com>
In-Reply-To: <Pine.BSF.4.21.0107301549520.5504-100000@localhost>

next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, 30 Jul 2001, Alexander V P wrote:

> hi,
> i've compiled and it didn't work. error:sysctlbyname(): Operation not
> supported
> any idea?
> tia,
> alex
>

I have not tried to compile this on 4.3. However, I did test
it on my 3.4R box and it compiled just fine.
Has that call been replaced or renamed?

Jim

> On Mon, 30 Jul 2001, Jim Freeze wrote:
>
> > 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 <oogali@intranova.net>
> >  */
> >
> > /* 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 <stdio.h>
> > #include <stdlib.h>
> > #include <string.h>
> > #include <unistd.h>
> > #include <sys/types.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 - 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
> >
>
>


=========================================================
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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.32.0107301827540.7577-100000>