关闭看门狗-喂狗

有时候程序运行过程中需要单独关闭看门狗:

#include <fcntl.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <linux/watchdog.h>
#define TIMEOUT 10
#define WDT_DEVICE_FILE "/dev/watchdog"
int main(void)
{
    int g_watchdog_fd = -1;
    int timeout = 0;
    char arg = 1;

    g_watchdog_fd = open(WDT_DEVICE_FILE, O_RDWR);
    if (!g_watchdog_fd)
    {
        printf("Error in file open WDT device file(%s)...\n", WDT_DEVICE_FILE);

        return 0;
    }
    ioctl(g_watchdog_fd, WDIOC_SETOPTIONS, WDIOS_ENABLECARD);
#if 1 
    ioctl(g_watchdog_fd, WDIOC_GETTIMEOUT, &timeout);
    printf("default timeout %d sec.\n", timeout);

    printf("We reset timeout as %d sec.\n", TIMEOUT);
    timeout = TIMEOUT;
    ioctl(g_watchdog_fd, WDIOC_SETTIMEOUT, &timeout);
    ioctl(g_watchdog_fd, WDIOC_GETTIMEOUT, &timeout);
    if (timeout != TIMEOUT)
    {
        printf("WDT timeout reset error.\n");
        return 1;
    }

    while (1)
    {
	write(g_watchdog_fd, &arg, sizeof(arg));
        ioctl(g_watchdog_fd, WDIOC_KEEPALIVE, 0);
        sleep(2);
    }
#endif
    ioctl(g_watchdog_fd, WDIOC_SETOPTIONS, WDIOS_DISABLECARD);
    close(g_watchdog_fd);
    printf("watchdog_disable_dog!!!\n");
    return 0;
}


  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值