06-25-2019, 04:04 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.cThank you !
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;
}