因爲防止linux系統下程序忽然意外終止或是陷入死循環等狀況,啓用看門狗機制,出現問題的時候機器重啓。linux
查看liux系統下是否有 /dev/watchdog
控制句柄this
ls /dev/watchdog
代碼段code
int fd = open("/dev/watchdog", O_WRONLY); if(fd == -1){ printf("open watchdog error \n\n\n"); return false; } int timeout; timeout = 15; ioctl(fd, WDIOC_SETTIMEOUT, &timeout); //設置超時 printf("The timeout was set to %d seconds\n", timeout);
ioctl(this->fd, WDIOC_KEEPALIVE);
使用定時的方式運行以上語句,延時時間必須小於超時時間。io