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. 因此,我们可以 ...
随机推荐
- java解决动态的锁顺序死锁的方案
直接上代码 public class Test3 { public static Object fromAccount = new String("1"); public stat ...
- oracle分析函数系列之sum(col1) over(partition by col2 order by col3):实现分组汇总或递增汇总
语法:sum(col1) over(partition by col2 order by col3 ) 准备数据: DEPT_ID ENAME SAL1 1000 ...
- sublime text 快捷键记录
sublime常用快捷键 Ctrl+D 选词 (反复按快捷键,即可继续向下同时选中下一个相同的文本进行同时编辑) Ctrl+G 跳转到相应的行 Ctrl+J 合并行(已选择需要合并的多行时) Ctrl ...
- 零基础入门学习Python(5)--闲聊之Python的数据类型
前言 本次主要闲聊一下python的一些数值类型,整型(int),浮点型(float),布尔类型(bool),还有e记法(科学计数法),也是属于浮点型. 数值类型介绍 整型 整型就是我们平时所说的整数 ...
- PHP实现微信第三方登录的方法
本文实例讲述了PHP版微信第三方实现一键登录及获取用户信息的方法.分享给大家供大家参考,具体如下: 注意,要使用微信在第三方网页登录是需要“服务号”才可以哦,所以必须到官方申请 一开始你需要进入微信公 ...
- xtrbackup备份mysql
mysqldump备份方式是采用逻辑备份,但是它最大的缺陷就是备份和恢复速度慢对于一个小于50G的数据库而言,这个速度还是能接受的,但如果数据库非常大,那再使用mysqldump备份就不太适合了. x ...
- mysql常用命令用法
Mysql帮助文档地址:http://dev.mysql.com/doc/ 1.创建数据库: create database database_name; 2.选择数据库: use database_ ...
- SSH配置—Linux下实现免密码登录
首先,假设我们有两台服务器,服务器名称分别是 master 和 slave1,我们现在需要做的就是在服务器 master 上面登录 服务器 slave1 不需要输入密码就可以登录成功,如下图所示. 下 ...
- 【BZOJ2142】礼物(扩展lucas定理,中国剩余定理合并方程)
题意:有n件礼物,m个人,每个人分别需要w[i]件礼物,求分礼物的不同方案数 mod P 提示:设P=p1^c1 * p2^c2 * p3^c3 * … *pt ^ ct,pi为质数. 1≤n≤10^ ...
- Free Goodies UVA - 12260
Petra and Jan have just received a box full of free goodies, and want to divide the goodies between ...