Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

sysctlbyname( "hw.availcpu" ) fails



When I try to use sysctlbyname with "hw.availcpu", I get an error but when I use { CTL_HW, HW_AVAILCPU } with sysctl, it succeeds. Here is my test case:

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

int main()
{
        int mib[2] = { CTL_HW, HW_AVAILCPU };
        int cpus;
        size_t size = sizeof( cpus );

        if( sysctl(mib, 2, &cpus, &size, NULL, 0) == -1 )
                perror( "sysctl" );
        else
                printf( "sysctl: %d\n", cpus );
        size = sizeof( cpus );
        if( sysctlbyname("hw.availcpu", &cpus, &size, NULL, 0) == -1 )
                perror( "sysctlbyname" );
        else
                printf( "sysctlbyname: %d\n", cpus );
        size = 2;
        if( sysctlnametomib("hw.availcpu", mib, &size) == -1 )
                perror( "sysctlnametomib" );
        size = sizeof( cpus );
        if( sysctl(mib, 2, &cpus, &size, NULL, 0) )
                perror( "sysctl2" );
        else
                printf( "sysctl2: %d\n", cpus );
        return 0;
}

When I run it, I get:
$ ./a.out
sysctl: 2
sysctlbyname: No such file or directory
sysctlnametomib: No such file or directory
sysctl2: 2
$ sysctl hw.availcpu hw.activecpu
hw.availcpu = 2
hw.activecpu: 2

What is the difference between activecpu and availcpu, e.g., why does one have an equal sign and the other a colon?

A similar issue I found in the list archives was <http:// lists.apple.com/archives/darwin-development/2003/Aug/msg00256.html>.

Just to be clear about this, I only want the information for my own debugging purposes. Absolutely nothing in the code makes any decisions based on the number of cpus.

--
Steve Checkoway




Attachment: smime.p7s
Description: S/MIME cryptographic signature

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/darwin-dev/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.