Linux watchdog 6300esb
基本原理:
Linux 自带了一个 watchdog 的实现,用于监视系统的执行,包含一个内核 watchdog module 和一个用户空间的 watchdog 程序。内核 watchdog 模块通过 /dev/watchdog 这个字符设备与用户空间通信。用户空间程序一旦打开 /dev/watchdog 设备(俗称“开门放狗”),就会导致在内核中启动一个1分钟的定时器(系统默认时间),此后。用户空间程序须要保证在1分钟之内向这个设备写入数据(俗称“定期喂狗”)。每次写操作会导致又一次设定定时器。
假设用户空间程序在1分钟之内没有写操作。定时器到期会导致一次系统
reboot 操作(“狗咬人了”呵呵)。通过这样的机制,我们能够保证系统核心进程大部分时间都处于执行状态,即使特定情形下进程崩溃。因无法正常定时“喂狗”,Linux系统在看门狗作用下又一次启动(reboot),核心进程又执行起来了。多用于嵌入式系统。
以上原理为watchdog的基本原理,其他类型的watchdog也是依照这个原理实现的。
实例測试:
比方測试通过的6300esb
设备情况例如以下:
[root@vm01 ~]# lspci
00:00.0 Host bridge: Intel Corporation 440FX - 82441FX PMC [Natoma] (rev 02)
00:01.0 ISA bridge: Intel Corporation 82371SB PIIX3 ISA [Natoma/Triton II]
00:01.1 IDE interface: Intel Corporation 82371SB PIIX3 IDE [Natoma/Triton II]
00:01.2 USB controller: Intel Corporation 82371SB PIIX3 USB [Natoma/Triton II] (rev 01)
00:01.3 Bridge: Intel Corporation 82371AB/EB/MB PIIX4 ACPI (rev 03)
00:02.0 VGA compatible controller: Cirrus Logic GD 5446
00:03.0 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL-8139/8139C/8139C+ (rev 20)
00:04.0 Audio device: Intel Corporation 82801FB/FBM/FR/FW/FRW (ICH6 Family) High Definition Audio Controller (rev 01)
00:05.0 Communication controller: Red Hat, Inc Virtio console
00:06.0 RAM memory: Red Hat, Inc Virtio memory balloon
00:07.0 System peripheral: Intel Corporation 6300ESB Watchdog Timer
[root@vm01 ~]# dmesg|grep 6300
i6300ESB timer: Intel 6300ESB WatchDog Timer Driver v0.04
i6300ESB timer: initialized (0xffffc90000e8c000). heartbeat=30 sec (nowayout=0)
[root@vm01 ~]# lsmod|grep softdog
[root@vm01 ~]# lsmod|grep watchdog
[root@vm01 ~]# ps -ef|grep watchdog
root 6 2 0 01:59 ?
00:00:00 [watchdog/0]
root 1748 1711 0 02:28 pts/0 00:00:00 grep watchdog
[root@vm01 ~]# lsmod|grep 6300
i6300esb 5669 0
close(fd_watchdog);
总体程序例如以下:
#include <unistd.h>
#include <sys/stat.h>
#include <syslog.h>
#include <errno.h>
#include <sys/types.h>
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
int main(int argc,char** argv)
{
//1、打开 /dev/watchdog 设备(“开门放狗”):
int fd_watchdog = open("/dev/watchdog",O_WRONLY);
if(fd_watchdog == -1)
{
int err = errno;
printf("\n!! failed to open /dev/watchdog,errno:%d,%s \n",err,strerror(err));
syslog(LOG_WARNING,"failed to open /dev/watchdog,errno:%d,%s",err,strerror(err));
}
//2、每隔一段时间向 /dev/watchdog 设备写入数据(“定期喂狗”):
if(fd_watchdog >= 0)
{
while(1)
{
sleep(10);
static unsigned char food = 0;
ssize_t earten = write(fd_watchdog,&food,1);
if(earten != 1)
{
puts("\n!!! failed feeding watchdog");
syslog(LOG_WARNING,"failted feeding watchdog");
}
}
}
close(fd_watchdog);
}
[root@vm01 watchdog]# gcc watchdog.c -o watchdog
[root@vm01 watchdog]# ./watchdog &
[1] 1790
[root@vm01 watchdog]#
使系统崩溃:
[root@vm01 ~]# echo c > /proc/sysrq-trigger
这时候系统会自己主动又一次启动。
假设通过spice连接的系统,会看到先出现系统崩溃而出现的非常多字符提示。一会系统就会又一次启动。
Linux watchdog 6300esb的更多相关文章
- Linux Watchdog Test Program
/*********************************************************************** * Linux Watchdog Test Progr ...
- linux watchdog demo hacking
/********************************************************************** * linux watchdog demo hackin ...
- Linux watchdog
使用 watchdog 构建高可用性的 Linux 系统及应用https://www.ibm.com/developerworks/cn/linux/l-cn-watchdog/index.html ...
- Linux watchdog 关闭退出功能
Linux 程序退出的时候,程序是会把 watchdog 调用 release 功能.
- 基于S3C2440的嵌入式Linux驱动——看门狗(watchdog)驱动解读
本文将介绍看门狗驱动的实现. 目标平台:TQ2440 CPU:s3c2440 内核版本:2.6.30 1. 看门狗概述 看门狗其实就是一个定时器,当该定时器溢出前必须对看门狗进行"喂狗“,如 ...
- watchdog机制
转自:http://blog.sina.com.cn/s/blog_4dff871201012yzh.html 什么是Watchdog? Watchdog,又称watchdog timer,是计算机可 ...
- Qt 控制watchdog app hacking
/************************************************************************** * Qt 控制watchdog app hack ...
- xrdp远程 & watchdog 启用与测试 & WebRTC
sudo apt-get install xrdp sudo apt-get install vnc4server tightvncserver echo "xfce4-session&qu ...
- [虚拟化/云][全栈demo] 为qemu增加一个PCI的watchdog外设(七)
目标: 1. 完成最终的设备驱动,增加具体的watchdog设备操作的代码. 测试代码: 代码最终实现见cwd_demo.c 代码只实现了read与write. 没有实现ioctl. 因此,我们可以 ...
随机推荐
- CSS 实现斑马条纹
Part.1 linear-gradient() linear-gradient() 函数用于创建一个线性渐变的 "图像".为了创建一个线性渐变,你需要设置一个起始点和一个方向(指 ...
- Spring Data Redis入门示例:Hash操作(七)
将对象存为Redis中的hash类型,可以有两种方式,将每个对象实例作为一个hash进行存储,则实例的每个属性作为hash的field:同种类型的对象实例存储为一个hash,每个实例分配一个field ...
- Ztree勾选节点后取消勾选其父子节点
前言: Ztree官方给的API可以设置勾选一个节点的同时勾选子节点或者父节点,也可以设置不影响父子节点,即将chkboxType设置为{"Y":"",&quo ...
- 零基础入门学习Python(28)--文件
知识点 Python中使用open(...)这个内置函数来打开文件,并返回文件对象 open()函数参数说明: open(file, mode='r', buffering=-1, encoding= ...
- eclipse 导入svn项目并添加server
1.打开svn资源库 window-->show view-->other-->svn-->svn资源库 2.控制台选中文件夹右键-->检出为--finish 3.添加服 ...
- java 通过反射机制调用某个类的方法
package net.xsoftlab.baike; import java.lang.reflect.Method; public class TestReflect { public s ...
- java 几种拼接字符串的效率问题
拼接字符串,大致有3个class可以用,他们是String, StringBuffer,StringBuilder, StringBuilder是1.5中来代替StringBuffer的.检验方法如下 ...
- z_algorithm
//对于字符串a的每个后缀,匹配它与a的第一个后缀的最长公共前缀,复杂度线性void z_algorithm(char *a,int len) { z[]=len; ,j=,k;i<len;i= ...
- multi cookie & read bug
js cookie multi cookie & read bug document.cookie; // "access_token_test=eyJhbGciOiJIUzI1Ni ...
- CSU 1554 SG Value (集合类的学习)
题目大意: 2种操作 1 a:往集合中添加一个元素a 2: 询问这个集合中的元素任意组合相加所不能得到的最小数的值 这道题总是不断地去找当前所能处的最小值能否被当前的最小值加上其前部的一堆可抵达数到达 ...