linux看门狗使用
程序员文章站
2022-07-12 10:19:02
...
参考
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);
}
上一篇: linux驱动编写(看门狗)
下一篇: 【STM32】(2) 按键输入实验