415-device-driver/Test/Mohammed_UzairHamed_HW6_main.c
2024-12-05 22:36:41 -08:00

29 lines
554 B
C

#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
#define DEVICE_NAME "/dev/temp_monitor"
#define IOCTL_GET_TEMP _IOR('t', 1, int)
int main() {
int fd;
int temp;
fd = open(DEVICE_NAME, O_RDONLY);
if (fd < 0) {
perror("Failed to open the device");
return -1;
}
if (ioctl(fd, IOCTL_GET_TEMP, &temp) < 0) {
perror("Failed to get temperature");
close(fd);
return -1;
}
printf("Current CPU Temperature: %d°C\n", temp);
close(fd);
return 0;
}