watchdog概述
来源:互联网 发布:淘宝申请部分退款 编辑:程序博客网 时间:2024/06/05 20:11
http://blog.csdn.net/wyzxg/article/details/5579415
watchdog工作原理:
在系统运行以后也就启动了看门狗的计数器,看门狗就开始自动计数,如果到了一定的时间还不去复位看门狗,
那么看门狗计数器就会溢出从而引起看门狗中断,造成系统复位。所以在使用有看门狗的芯片时要注意复位看门狗。
看门狗有硬件和软件的。常见的硬件看门狗是PCI接口和USB接口,体积很小。
Linux 自带了一个 watchdog 的软件程序,用于监视系统的运行,它包括一个内核 watchdog module
和一个用户空间的 watchdog 程序。
内核 watchdog 模块
通过 /dev/watchdog 这个字符设备与用户空间通信。用户空间程序一旦打开 /dev/watchdog 设备,
就会导致在内核中启动一个 1分钟的定时器,此后,用户空间程序需要保证在 1分钟之内向这个设备写入数据,每次写
操作会导致重新设定定时器。如果用户空间程序在 1分钟之内没有写操作,定时器到期会导致一次系统 reboot 操作。
用户空间程序可通过关闭 /dev/watchdog 来停止内核中的定时器。
用户空间的 watchdog 守护进程:
在用户空间,还有一个叫做 watchdog 的守护进程,它可以定期对系统进行检测,包括:
* Is the process table full?
* Is there enough free memory?
* Are some files accessible?
* Have some files changed within a given interval?
* Is the average work load too high?
* Has a file table overflow occurred?
* Is a process still running? The process is specified by a pid file.
* Do some IP addresses answer to ping?
* Do network interfaces receive traffic?
* Is the temperature too high? (Temperature data not always available.)
* Execute a user defined command to do arbitrary tests.
如果某项检测失败,则可能导致一次 soft reboot (模拟一次 shutdown 命令的执行),它还可以通过 /dev/watchdog 来触发内核 watchdog 的运行。
内核级”watchdog”与用户空间的”watchdog”的主要区别是,内核态的”watchdog”抗干扰能力强,运行稳定。
例子1:
- /*
- * Watchdog usage.
- * Author: Serval Li
- * Date: Jun 27th, 2012
- * */
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <sys/ioctl.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #include <signal.h>
- #include <linux/types.h>
- #include <linux/watchdog.h>
- int main(void)
- {
- int fd;
- int timeout, flag;
- char cmd[256];
- if ((fd = open("/dev/watchdog", O_RDWR)) < 0) {
- perror("");
- exit(1);
- }
- ioctl(fd, WDIOC_GETTIMEOUT, &timeout);
- printf("Default timeout: %d\n", timeout);
- timeout = 12;
- printf("Set timeout to %d\n", timeout);
- ioctl(fd, WDIOC_SETTIMEOUT, &timeout);
- ioctl(fd, WDIOC_GETTIMEOUT, &timeout);
- printf("New timeout: %d\n", timeout);
- flag = fcntl(0, F_GETFL, 0);
- flag |= O_NONBLOCK;
- if (fcntl(0, F_SETFL, flag) < 0) { /* fgets no-block now */
- perror("Set stdin to non-block fails.");
- exit(1);
- }
- while (1) {
- ioctl(fd, WDIOC_KEEPALIVE, 0);
- fgets(cmd, sizeof(cmd) - 1, stdin);
- if(strncmp(cmd, "stop", 4) == 0)
- goto stopwd;
- sleep(timeout / 2);
- }
- stopwd:
- write(fd, "V", 1); /* This is "V", not "v"! */
- close(fd);
- printf("Close watchdog!");
- return 0;
- }
例子2:
- watchdog概述
- 嵌入式系统之WATCHDOG(看门狗)概述
- watchdog
- WatchDog
- Watchdog
- watchdog
- WatchDog
- watchdog
- Watchdog
- Watchdog
- Watchdog
- Watchdog, watchdog in Linux
- watchdog使用
- WatchDog Timer
- tombstone & watchdog
- linux watchdog
- linux watchdog
- watchdog linux
- 斐波那契数列的非递归实现(Java)
- Let's pay attention & join the Drill Project
- 程序员怎么才能提高代码编写速度?
- 2013年考研英语写作高分必备35个句型总结
- POJ 3352 Road Construction 无向图割边 + 缩点
- watchdog概述
- C#多线程操作界面控件的解决方案
- javascript 取form元素、form元素中的input元素值(有待完善)
- SSL握手过程
- Assert
- Hadoop是什么、它要解决的问题及HDFS的架构(提供完整视频教程讲解)
- 以 rsync 進行同步鏡像備份
- Makefile编译选项
- Apache Drill Could Power Faster Through Data