watchdog-simple.c 346 B

123456789101112131415161718192021222324
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <fcntl.h>
  5. int main(void)
  6. {
  7. int fd = open("/dev/watchdog", O_WRONLY);
  8. int ret = 0;
  9. if (fd == -1) {
  10. perror("watchdog");
  11. exit(EXIT_FAILURE);
  12. }
  13. while (1) {
  14. ret = write(fd, "\0", 1);
  15. if (ret != 1) {
  16. ret = -1;
  17. break;
  18. }
  19. sleep(10);
  20. }
  21. close(fd);
  22. return ret;
  23. }