cputemp.c 967 B

12345678910111213141516171819202122232425262728293031323334353637
  1. /*
  2. cputemp - display the CPU's temperature without the need for ACPI, etc.
  3. (also the *only* way to read it in a Raspberry Pi SOC!)
  4. Copyright 2022 kzimmermann - https://tilde.town/~kzimmermann/
  5. This program is Free Software licensed under the GNU GPLv3 or later.
  6. For more information, please see https://www.gnu.org/licenses
  7. */
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. // Change this to the location of the equivalent file in your own system:
  11. const char *THERMFILE = "/sys/class/thermal/thermal_zone0/temp";
  12. int main(int argc, char **argv)
  13. {
  14. FILE *fp;
  15. float temperature = 0;
  16. fp = fopen(THERMFILE, "r");
  17. if (fp == NULL) {
  18. printf("Error: temperature file '%s' not found.\n", THERMFILE);
  19. printf("Look up where that file resides in your system, then change it in the source accordingly.\n");
  20. return 1;
  21. }
  22. fscanf(fp, "%f", &temperature);
  23. fclose(fp);
  24. printf("%.2f\n", temperature / 1000);
  25. return 0;
  26. }