看门狗应用程序
发布日期:2022-02-01 13:46:26
浏览次数:38
分类:技术文章
本文共 1168 字,大约阅读时间需要 3 分钟。
#include <stdio.h>
#include <stdlib.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <linux/watchdog.h>int main(int argc, char **argv)
{ int ret = 0; int index = 0 ; int timeout = 0; int enable_card = 0; int disable_card = 0; int fd = open("/dev/watchdog", O_WRONLY); if(fd == -1){ printf("open watchdog error \n\n\n"); return 0; }printf("open watchdog ok \n\n\n");
timeout = 15; ret = ioctl(fd, WDIOC_SETTIMEOUT, &timeout); //设置超时 if(0 != ret ) printf("WDIOC_SETTIMEOUT is err %d \n",ret); enable_card = WDIOS_ENABLECARD; ret = ioctl(fd, WDIOC_SETOPTIONS, &enable_card); if(0 != ret ) printf("WDIOS_ENABLECARD is err %d \n",ret); while(index < 5){ sleep(2); ret = ioctl(fd, WDIOC_KEEPALIVE, &timeout); if(0 != ret ) printf("feeding watchdog error:%d\n",ret); ret = ioctl(fd, WDIOC_SETTIMEOUT, &timeout); if(0 != ret ) printf("feeding watchdog error:%d\n",ret);sleep(1);
index++; printf("run index :%d\n",index);}
disable_card = WDIOS_DISABLECARD; ret = ioctl(fd, WDIOC_SETOPTIONS, &disable_card); if(0 != ret ) printf("WDIOS_DISABLECARD is err \n");close(fd);
return 1; }需要注意的是ioctl的传参的最后一个参数是指针,而不是一个变量,否则会返回报错,err : -14 就是bad adress
转载地址:https://blog.csdn.net/shidong007/article/details/107979423 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
能坚持,总会有不一样的收获!
[***.219.124.196]2024年04月09日 22时19分28秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
Vue事件处理_vue的事件处理超级方便_功能强大---vue工作笔记0011
2019-04-26
Vue表单数据自动收集---vue工作笔记0012
2019-04-26
Vue生命周期---vue工作笔记0013
2019-04-26