/**********************************************************************
* 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. List<t>中如何将指定元素的值放到第一位

    public static List<GCountryExtend> GetList() { try { var result = new List<GCountryExtend&g ...

  2. 【Spring-boot多数据库】Spring-boot JDBC with multiple DataSources sample

    application.properties spring.ds_items.driverClassName=org.postgresql.Driver spring.ds_items.url=jdb ...

  3. Linux C程序的编译过程

    Linux C程序的编译过程 学习一门语言程序,本人觉得还是得学习它的编译规则,现在,通过小例子小结下自己对C编译的认识. /*test.c     了解C程序的编译*/ #include <s ...

  4. 滤镜简单demo(转,供参考)

    NSURL *iamgeUrl = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"default" ...

  5. phpd读取txt文件(自动解析换行)

    <form id="form" method="post" action="whois.php"> <?php $newf ...

  6. ExtJS4.2学习(11)可拖放的表格(转)

    鸣谢:http://www.shuyangyang.com.cn/jishuliangongfang/qianduanjishu/2013-11-18/180.html --------------- ...

  7. ajax返回正个页面

       

  8. GIT:本地有更改,但强制作远程仓库里作更新

    有时,紧急线上修改时,这个功能有用处的. git fetch --all git reset --hard origin/master ================ git reset --har ...

  9. Mybatis代码生成器 xml配置文件 连接SQL SERVER 2005

    <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE generatorConfiguratio ...

  10. linux ps查看进程命令

    linux ps查看进程命令ps命令作用:将某个时间点的程序运作情况撷取下来 实例: [root@linux ~]# ps aux [root@linux ~]# ps -lA [root@linux ...