Re: sysctl(3) and sysctl(8) discrepancies



In the last episode (Apr 19), Mathieu Prevot said:
Hello,

I have FreeBSD 6.1-RC #27: Wed Apr 19 02:08:00 CEST 2006 amd64 and I have 3
different outputs about hw.ncpu:

`sysctl hw.ncpu` gives me:

'hw.ncpu: 2'


and I have:

hw.ncpu = 6
hw.ncpu = 3


with:

#include <stdlib.h>
#include <sys/types.h>
#include <sys/sysctl.h>

main()
{
int ncpu[1];
size_t len;

len=sizeof(int);
sysctlnametomib("hw.ncpu",ncpu,&len);

You want sysctlbyname() here instead. sysctlnametomib() returns a
pointer to a mib array that you can pass to the sysctl() function
later. Saves having to parse the string every time if you are looking
up the same sysctl repeatedly.

sysctlbyname("hw.ncpu", &ncpu, &len, NULL, 0);

HW_NCPU is the mib number for hw.ncpu if you want to build the mib
array manually.

--
Dan Nelson
dnelson@xxxxxxxxxxxxxxx
_______________________________________________
freebsd-hackers@xxxxxxxxxxx mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@xxxxxxxxxxx"



Relevant Pages

  • Re: sensors framework continued (architecture)
    ... provided reasons why a fd based approach is better than a sysctl MIB ... I think a MIB approach is much more usefull between "Single-system sensors ... expected to be used as a configuration interface to define a kernel ...
    (freebsd-arch)
  • Re: RFC: Adding a hw.features[2] sysctl
    ... Igor Mozolevsky wrote: ... sysctl() could fill a cpu features bitmask for programs. ... Make one contiguous bitmask that include all of them. ... That way the bitmask can sit in one sysctl MIB. ...
    (freebsd-current)
  • Re: RFC: Adding a hw.features[2] sysctl
    ... sysctl() could fill a cpu features bitmask for programs. ... So how would you MIB these: ... CPU: Dual Core AMD OpteronProcessor 280 ...
    (freebsd-current)