36 lines
833 B
C
36 lines
833 B
C
#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 main() {
|
|
int fd, timeout;
|
|
|
|
// 打开看门狗设备文件
|
|
fd = open("/dev/watchdog", O_WRONLY | O_NONBLOCK);
|
|
if (fd == -1) {
|
|
perror("看门狗 ");
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
|
|
// 设置超时时间为10秒
|
|
timeout = 60;
|
|
|
|
// 设置超时时间并获取实际超时时间
|
|
ioctl(fd, WDIOC_SETTIMEOUT, &timeout);
|
|
ioctl(fd, WDIOC_GETTIMEOUT, &timeout);
|
|
// printf("设置的看门狗超时时间为 %d\n", timeout);
|
|
|
|
// 喂狗并等待一段时间
|
|
ioctl(fd, WDIOC_KEEPALIVE, &timeout);
|
|
// printf("喂狗了\n");
|
|
sleep(0.1);
|
|
|
|
// 关闭看门狗设备文件
|
|
close(fd);
|
|
return 0;
|
|
} |