博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
linux watchdog demo hacking
阅读量:7078 次
发布时间:2019-06-28

本文共 1755 字,大约阅读时间需要 5 分钟。

/********************************************************************** *                    linux watchdog demo hacking * 说明: *     本文主要解析linux watchdog大概应该如何操作。 * *                                    2016-3-28 深圳 南山平山村 曾剑锋 *********************************************************************/#include 
#include
#include
#include
#include
#include
#include
#include
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 == -1) { fprintf(stderr, "Watchdog device not enabled.\n"); fflush(stderr); exit(-1); } if (argc > 1) { // 关闭watchdog if (!strncasecmp(argv[1], "-d", 2)) { flags = WDIOS_DISABLECARD; ioctl(fd, WDIOC_SETOPTIONS, &flags); fprintf(stderr, "Watchdog card disabled.\n"); fflush(stderr); exit(0); // 使能watchdog } else if (!strncasecmp(argv[1], "-e", 2)) { flags = WDIOS_ENABLECARD; ioctl(fd, WDIOC_SETOPTIONS, &flags); fprintf(stderr, "Watchdog card enabled.\n"); fflush(stderr); exit(0); } else { fprintf(stderr, "-d to disable, -e to enable.\n"); fprintf(stderr, "run by itself to tick the card.\n"); fflush(stderr); exit(0); } } else { fprintf(stderr, "Watchdog Ticking Away!\n"); fflush(stderr); } while(1) { // 每一秒喂狗一次 keep_alive(); sleep(1); }}

 

转载地址:http://zhpml.baihongyu.com/

你可能感兴趣的文章
linux环境中设置jacoco覆盖率
查看>>
使用 Google Cloud 上的 tf.Transform 对 TensorFlow 管道模式进行预处理
查看>>
跳表在手天下我有之ConcurrentSkipListMap
查看>>
一篇文章,从源码深入详解ThreadLocal内存泄漏问题
查看>>
PHP算法:一个数字平分为N份,并且总值相等
查看>>
linux/unix编程手册-1_5
查看>>
Mac OS 解决 /usr/bin/sudo must be owned by uid 0 问题
查看>>
第5条:避免创建不必要的对象
查看>>
使用UltraISO制作U盘启动盘
查看>>
过滤器第二篇【编码、敏感词、压缩、转义过滤器】
查看>>
半小时轻松玩转WebGL滤镜技术系列(一)
查看>>
实现一个可管理、增发、兑换、冻结等高级功能的代币
查看>>
【vue源码篇】filter源码详解
查看>>
React Native 报错
查看>>
【android精选】图片涂鸦下拉加载地图大集合五子棋游戏自定义上下文菜单源码...
查看>>
Git bug分支与多人协作
查看>>
反转单链表的方法
查看>>
python-14-描述符应用和类的装饰器
查看>>
帖子回复列表缓存优化日志
查看>>
单元测试利器Mockito框架
查看>>