sysctlbyname( "hw.availcpu" ) fails
site_archiver@lists.apple.com Delivered-To: darwin-dev@lists.apple.com #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 -- Steve Checkoway _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-dev mailing list (Darwin-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-dev/site_archiver%40lists.appl... This email sent to site_archiver@lists.apple.com 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: 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. smime.p7s
participants (1)
-
Steve Checkoway