/** Watchdog usage. * Author: serval li * Date: Jun 27th, 2012 **/# include <stdio. h> # include <string. h> # include <stdlib. h> # include <unistd. h> # include <sys/IOCTL. h> # include <sys/types. h> # include <sys/STAT. h> # include <fcntl. h> # include <signal. h> # include <Linux/types. h> # include <Linux/watchdog. h> int main (void) {int FD; int timeout, flag; char cmd [256]; If (FD = open ("/dev/watchdog", o_rdwr )) <0 ){ Perror (""); exit (1);} IOCTL (FD, wdioc_gettimeout, & timeout); printf ("default timeout: % d \ n", timeout ); timeout = 12; printf ("set timeout to % d \ n", timeout); IOCTL (FD, wdioc_settimeout, & timeout); IOCTL (FD, wdioc_gettimeout, & timeout ); printf ("New Timeout: % d \ n", timeout); flag = fcntl (0, f_getfl, 0); flag | = o_nonblock; If (fcntl (0, f_setfl, flag) <0) {/* fgets no-block now */perror ("set stdi N to non-block fails. "); exit (1);} while (1) {IOCTL (FD, wdioc_keepalive, 0); fgets (CMD, sizeof (CMD)-1, stdin ); if (strncmp (CMD, "stop", 4) = 0) goto stopwd; sleep (timeout/2);} stopwd: Write (FD, "V", 1 ); /* this is "V", not "V "! */Close (FD); printf ("Close watchdog! "); Return 0 ;}
CodeSave it first and use the watchdog implemented by softdog. C. Its kernel module is named softdog. Ko and is located under/lib/modules/$ kernelver/kernel/Drivers/watchdog.