#include #include #include #define KELV_ZEROC 2732 #define KELV_TO_CEL(x) ((x) - KELV_ZEROC) #define CEL_TO_FAR(x) ((x) * 9 / 5 + 320) #define KELV_TO_FAR(x) CEL_TO_FAR(KELV_TO_CEL((x))) int main(int ac, char **av) { int celsius, far, kelvin, error; size_t kelvinlen = sizeof(kelvin); /* * Use sysctl interface to get temperature. */ error = sysctlbyname("hw.acpi.thermal.tz0.temperature", &kelvin, &kelvinlen, NULL, 0); if (error == -1) err(1, "sysctlbyname (hw.acpi.thermal)"); celsius = KELV_TO_CEL (kelvin); far = CEL_TO_FAR (celsius); printf("ACPI Thermal Zone Information\n"); printf("System temperature = %d.%d K %d.%d C %d.%d F\n", kelvin / 10, kelvin % 10, celsius / 10, celsius % 10, far / 10, far % 10); }