參考
dev/watchdog和dev/watchdog0 是同一個設備
Linux Watchdog 機制
[watchdog]內核失敗的重啓方案
使用
- dev/watchdog和dev/watchdog0是同一個設備,dev/watchdog來兼容老的接口
- Magic關閉特性,關掉看門狗文件句柄前如果寫入字母V,則關掉句柄後自動關閉看門狗使用
echo –n V >/dev/watchdog
,-n使echo不在結尾發送回車
喂狗方法,write調用,
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
int main(void)
{
int fd = open("/dev/watchdog", O_WRONLY);
int ret = 0;
if (fd == -1) {
perror("watchdog");
exit(EXIT_FAILURE);
}
while (1) {
ret = write(fd, "\0", 1);
if (ret != 1) {
ret = -1;
break;
}
sleep(10);
}
close(fd);
return ret;
}
或者ioctl調用,
while (1) {
ioctl(fd, WDIOC_KEEPALIVE, 0);
sleep(10);
}