/**********************************************************************
* linux watchdog demo hacking
* 说明:
* 本文主要解析linux watchdog大概应该如何操作。
*
* 2016-3-28 深圳 南山平山村 曾剑锋
*********************************************************************/ #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/types.h>
#include <linux/watchdog.h> int fd; /*
* This function simply sends an IOCTL to the driver, which in turn ticks
* the PC Watchdog card to reset its internal timer so it doesn't trigger
* a computer reset.
* 这个函数仅仅是发送一个IOCTL命令给驱动,重新启动Watchdog的内部时钟计数器,
* 这样就不会导致系统重启。
*/
static void keep_alive(void)
{
int dummy; ioctl(fd, WDIOC_KEEPALIVE, &dummy);
} /*
* The main program. Run the program with "-d" to disable the card,
* or "-e" to enable the card.
* 主程序,通过传递参数-d来关闭watchdog,-e来打开watchdog。
*/
int main(int argc, char *argv[])
{
int flags; // 打开设备节点
fd = open("/dev/watchdog", O_WRONLY);
if (fd == -) {
fprintf(stderr, "Watchdog device not enabled.\n");
fflush(stderr);
exit(-);
} if (argc > ) {
// 关闭watchdog
if (!strncasecmp(argv[], "-d", )) {
flags = WDIOS_DISABLECARD;
ioctl(fd, WDIOC_SETOPTIONS, &flags);
fprintf(stderr, "Watchdog card disabled.\n");
fflush(stderr);
exit();
// 使能watchdog
} else if (!strncasecmp(argv[], "-e", )) {
flags = WDIOS_ENABLECARD;
ioctl(fd, WDIOC_SETOPTIONS, &flags);
fprintf(stderr, "Watchdog card enabled.\n");
fflush(stderr);
exit();
} else {
fprintf(stderr, "-d to disable, -e to enable.\n");
fprintf(stderr, "run by itself to tick the card.\n");
fflush(stderr);
exit();
}
} else {
fprintf(stderr, "Watchdog Ticking Away!\n");
fflush(stderr);
} while() {
// 每一秒喂狗一次
keep_alive();
sleep();
}
}

linux watchdog demo hacking的更多相关文章

  1. Linux watchdog

    使用 watchdog 构建高可用性的 Linux 系统及应用https://www.ibm.com/developerworks/cn/linux/l-cn-watchdog/index.html ...

  2. linux SPI bus demo hacking

    /********************************************************************** * linux SPI bus demo hacking ...

  3. Linux SocketCan client server demo hacking

    /*********************************************************************** * Linux SocketCan client se ...

  4. Qt 控制watchdog app hacking

    /************************************************************************** * Qt 控制watchdog app hack ...

  5. am335x Qt SocketCAN Demo hacking

    /*********************************************************************************** * am335x Qt Soc ...

  6. Cmockery macro demo hacking

    /********************************************************************* * Cmockery macro demo hacking ...

  7. Linux Watchdog Test Program

    /*********************************************************************** * Linux Watchdog Test Progr ...

  8. Qt QML referenceexamples attached Demo hacking

    /********************************************************************************************* * Qt ...

  9. Linux watchdog 关闭退出功能

    Linux 程序退出的时候,程序是会把 watchdog 调用 release 功能.

随机推荐

  1. Chrome浏览器安装插件提示(net::ERR_NAME_NOT_RESOLVED)

    在chrome的webstore中安装currently插件.使用goagentFQ后能正常访问,但出现"net::ERR_NAME_NOT_RESOLVED"错误. 该错误的含义 ...

  2. php源代码安装常见错误与解决办法分享

    错误:configure: error: libevent >= 1.4.11 could not be found 解决:yum -y install libevent libevent-de ...

  3. linux配置JDK(转载)

    转载自:http://blog.csdn.net/xinxin19881112/article/details/46816385 Linux CentOS 6.6安装JDK1.7 目录 1.下载JDK ...

  4. visio

    为您的产品密钥: 7DNWX-MRX4G-QCGX2-DG6BP-DC8RP   http://technet.microsoft.com/zh-cn/evalcenter/hh973399.aspx ...

  5. 第二好用的时间日期选择插件(jscal)

    这个是第二好用的了,支持鼠标滚动选择时间.功能很强大,文档:http://www.dynarch.com/jscal/ 效果图: <!DOCTYPE html PUBLIC            ...

  6. String类中的equals()方法

    在Java中,每一个对象都有一个地址空间,在这空间保存着这个对象的值. equals 比较的是值,==比较的地址以及值. 01: public class StringExample02: {03: ...

  7. 团体程序设计天梯赛-练习集L1-003. 个位数统计

    L1-003. 个位数统计 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 给定一个k位整数N = dk-1*10k-1 + . ...

  8. (转)struts2.0配置文件、常量配置详解

    一.配置: 在struts2中配置常量的方式有三种: 在struts.xml文件中配置 在web.xml文件中配置 在sturts.propreties文件中配置 1.之所以使用struts.prop ...

  9. leetcode6 Reverse Words in a String 单词取反

    Reverse Words in a String  单词取反 whowhoha@outlook.com Question: Given an input string s, reverse the ...

  10. 微软的Dll管理方案及其变迁(Side-by-side assembly)

    本文简要介绍Side-by-side assembly技术,探讨在插件技术中使用类似方法的可能. 什么是Side-ty-side Assembly Side-by-side assembly是Wind ...