linux看门狗使用

版权声明:转载请关注我的公众号-青儿创客基地 https://blog.csdn.net/Zhu_Zhu_2009/article/details/89313643

参考

dev/watchdog和dev/watchdog0 是同一个设备
Linux Watchdog 机制
[watchdog]内核失败的重启方案

使用

  1. dev/watchdog和dev/watchdog0是同一个设备,dev/watchdog来兼容老的接口
  2. 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); 
}

猜你喜欢

转载自blog.csdn.net/Zhu_Zhu_2009/article/details/89313643