# include # include # include /* This max value is related to the depth value of the oid. For example the leaf life in hw.acpi.battery.life is at depth 4 */ #define MAX_DEPTH 10 int main (int argc, char *argv[]) { int mib[MAX_DEPTH], len = MAX_DEPTH; int result; unsigned value; result = sysctlnametomib ("hw.acpi.battery.life", mib, &len); if (result == -1) { perror ("sysctlnametomib"); exit (-1); } len = sizeof(value); result = sysctl (mib, 4, &value, &len, NULL, 0); if (result == -1) { perror ("sysctl"); exit (-1); } printf ("value = %d\n", value); return 0; }