temp-monitor/Test/Mohammed_UzairHamed_HW6_main.c
2024-12-07 16:25:28 -08:00

31 lines
645 B
C

#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
#define IOCTL_GET_TEMP _IOR('t', 1, int)
int main() {
int fd, temp;
fd = open("/dev/temp_monitor", O_RDWR);
if (fd < 0) {
perror("Failed to open the device");
return -1;
}
if (ioctl(fd, IOCTL_GET_TEMP, &temp) == -1) {
perror("Failed to get temperature");
close(fd);
return -1;
}
if (temp == 0) {
printf("Couldn't determine current temperature. Are you in a virtual machine?\n");
} else {
printf("Current temperature: %d°C\n", temp);
}
close(fd);
return 0;
}