linux watchdog demo hacking
/**********************************************************************
* 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的更多相关文章
- Linux watchdog
使用 watchdog 构建高可用性的 Linux 系统及应用https://www.ibm.com/developerworks/cn/linux/l-cn-watchdog/index.html ...
- linux SPI bus demo hacking
/********************************************************************** * linux SPI bus demo hacking ...
- Linux SocketCan client server demo hacking
/*********************************************************************** * Linux SocketCan client se ...
- Qt 控制watchdog app hacking
/************************************************************************** * Qt 控制watchdog app hack ...
- am335x Qt SocketCAN Demo hacking
/*********************************************************************************** * am335x Qt Soc ...
- Cmockery macro demo hacking
/********************************************************************* * Cmockery macro demo hacking ...
- Linux Watchdog Test Program
/*********************************************************************** * Linux Watchdog Test Progr ...
- Qt QML referenceexamples attached Demo hacking
/********************************************************************************************* * Qt ...
- Linux watchdog 关闭退出功能
Linux 程序退出的时候,程序是会把 watchdog 调用 release 功能.
随机推荐
- List<t>中如何将指定元素的值放到第一位
public static List<GCountryExtend> GetList() { try { var result = new List<GCountryExtend&g ...
- 【Spring-boot多数据库】Spring-boot JDBC with multiple DataSources sample
application.properties spring.ds_items.driverClassName=org.postgresql.Driver spring.ds_items.url=jdb ...
- Linux C程序的编译过程
Linux C程序的编译过程 学习一门语言程序,本人觉得还是得学习它的编译规则,现在,通过小例子小结下自己对C编译的认识. /*test.c 了解C程序的编译*/ #include <s ...
- 滤镜简单demo(转,供参考)
NSURL *iamgeUrl = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"default" ...
- phpd读取txt文件(自动解析换行)
<form id="form" method="post" action="whois.php"> <?php $newf ...
- ExtJS4.2学习(11)可拖放的表格(转)
鸣谢:http://www.shuyangyang.com.cn/jishuliangongfang/qianduanjishu/2013-11-18/180.html --------------- ...
- ajax返回正个页面
- GIT:本地有更改,但强制作远程仓库里作更新
有时,紧急线上修改时,这个功能有用处的. git fetch --all git reset --hard origin/master ================ git reset --har ...
- Mybatis代码生成器 xml配置文件 连接SQL SERVER 2005
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE generatorConfiguratio ...
- linux ps查看进程命令
linux ps查看进程命令ps命令作用:将某个时间点的程序运作情况撷取下来 实例: [root@linux ~]# ps aux [root@linux ~]# ps -lA [root@linux ...