Try this app. Also attached the code for your reference.
sudo ./wdt 20 20
#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <sys/ioctl.h>
#include <linux/watchdog.h>
#define DEV_NAME "/dev/watchdog"
int main(int argc, char **argv) {
int interval, margin;
if (argc >= 2) interval = atoi(argv[1]);
if (argc >= 3) margin = atoi(argv[2]);
printf("watchdogd started (interval %d, margin %d)!\n", interval, margin);
int fd = open(DEV_NAME, O_RDWR|O_CLOEXEC);
if (fd == -1) {
fprintf(stderr, "watchdogd: Failed to open %s: %s\n", DEV_NAME, strerror(errno));
return 1;
}
int timeout = interval + margin;
int ret = ioctl(fd, WDIOC_SETTIMEOUT, &timeout);
if (ret) {
ret = ioctl(fd, WDIOC_GETTIMEOUT, &timeout);
if (ret) {
fprintf(stderr, "watchdogd: Failed to get timeout: %s\n", strerror(errno));
} else {
if (timeout > margin) {
interval = timeout - margin;
} else {
interval = 1;
}
fprintf(stderr, "watchdogd: Adjusted interval to timeout returned by driver: timeout %d, interval %d, margin %d\n",
timeout, interval, margin);
}
} else {
printf ("watchdogd: set timeout success\n");
}
return 0;
}
wdt.txt (9.76 KB)