03-15-2020, 08:44 AM
(03-31-2018, 06:30 PM)NicoD Wrote: I wrote this C program to monitor the CPU temp. Just put it in Geany or another C compiler, save it as a *.c file, I call it tempCheck.c
Then compile it and run it.
Code starts after this.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void sleep_ms(int milliseconds)
{
struct timespec ts;
ts.tv_sec = milliseconds / 1000;
ts.tv_nsec = (milliseconds % 1000) * 1000000;
nanosleep(&ts, NULL);
}
int main()
{
int nanosleep(const struct timespec * req, struct timespec * rem);
FILE *temperature;
double T;
while(1)
{
temperature = fopen("/sys/class/thermal/thermal_zone0/temp", "r");
if(temperature == NULL)
{
printf("Can't measure the cpu temperature");
}
else
{
fscanf(temperature, "%lf", &T);
T /= 1000;
system("clear");
printf("The cpu temperature is %6.3f C.\n", T);
fclose(temperature);
sleep_ms(500);
}
}return 0;
}
For those that don't want to compile a program, this can be done in two lines of bash ;-) :
Code:
temp=$(cat /sys/class/thermal/thermal_zone0/temp)
echo ${temp::-3}.${temp:(-3)} C