#include
#include
#include
#include
#include
#include
#include
void main(void)
{
int fd_watchdog=-1;
while (1)
{
// fd_watchdog = open("/dev/watchdog", O_WRONLY);
if(fd_watchdog == -1)
{
int err = errno;
printf("failed to open /dev/watchdog, errno: %d, %s\n", err, strerror(err));
fd_watchdog = open("/dev/watchdog", O_WRONLY);
// return;
}
else
{
printf("open watchdog success!\n");
}
// 每个一段时间向/dev/watchdog 设备写入数据(“定期喂狗”)
if(fd_watchdog >= 0)
{
static unsigned char food = 0;
ssize_t eaten = write(fd_watchdog, &food, 1);
if(eaten != 1)
{
printf("failed feeding watchdog\n");
}
else
{
printf("success feeded watchdog\n");
}
}
}
//close(fd_watchdog);
}