SOFT_WDT is a software-implemented Linux watchdog.
SOFT_WDT is an open source, free software.
: Http://sourceforge.net/projects/soft-wdt/files/latest/download?source=files
Main features of SOFT_WDT:
1. He can provide a large number of watchdog for user use;
2. The features of each watchdog can be set individually
After the SOFT_WDT code is compiled, a kernel module Soft_wdt.ko is generated.
After the module is loaded, a file is created/DEV/SOFT_WDT
User-state program, via system call open every time/DEV/SOFT_WDT is opened, it gets a watchdog,
The watchdog is operated by the FD returned by Open.
Each time the user calls the write system, writes any data to the FD and completes the dog feeding operation.
Some settings for the watchdog can be implemented if the following special data is written to FD.
<name>x</name> take a name for the watchdog. X is the name of the dog, such as Wangcai:).
<timeout>x</timeout> set the time-out period in seconds. x change to a specific value.
<stop_on_fd_close>x</stop_on_fd_close> sets whether the watchdog shuts down when FD is closed. X=1 Close; X=0 not close
<no_reboot>x</no_reboot> If the watchdog timeout is set, restart the system. X=1 no reboot; X=0 reboot
<stop_dog>x</stop_dog> Stop the watchdog. X=1 stop; X=0 do nothing
Here's how to compile and use this software
(a) module compilation
Method one, compile separately
Under the SOFT_WDT source directory, execute the following command
Make-c/path/to/kernel/source/dir m= ' pwd ' modules
Method Two, compile in the Linux kernel compilation system
1. Copy the soft_wdt.c to the drivers/watchdog/directory.
2. Append the following line of code to the kernel source Drivers/watchdog/makefile (in the Architecture independant section)
obj-$ (CONFIG_SOFT_WDT) + = SOFT_WDT.O
3. Append the following content to the kernel source Drivers/watchdog/kconfig (in the Architecture independant section)
Config SOFT_WDT
TriState "Soft_wdt-software watchdog timer"
Default m
Help
Software implemented watchdog timer, supporting mutiple dogs,
and supply some control mechanism.
To compile this driver as a module, choose M here:the
Module would be called Softdog.
4. Execute make menuconfig to enter the watchdog driver's selection interface, then exit directly and save the configuration.
5. Execute make modules, and then in the drivers/watchdog/directory, the module file is generated Soft_wdt.ko
(ii) Module loading
1. Load with default parameters (5 seconds timeout, log file is/var/log/soft_wdt.log)
Insmod Soft_wdt.ko
2. Specify parameter loading (5 seconds timeout, log file is/var/log/soft_wdt.log)
Insmod Soft_wdt.ko timeout=12 log_file= "/path/to/other/log_file"
(iii) User-state program using watchdog sample code
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#define SOFT_WDT_DEV "/DEV/SOFT_WDT"
int main (int argc, char *argv[])
{
int i;
int Fd=open ("/DEV/SOFT_WDT", o_wronly);
if (FD < 0)
{
printf ("Open%s failed\n", Soft_wdt_dev);
Exit (1);
}
printf ("Open%s succeed\n", Soft_wdt_dev);
/* Set dog name. It ' s heplful for review log file. */
Write (FD, "<name>my_dog</name>", strlen ("<name>my_dog</name>"));
/* Set timeout to 123 seconds */
Write (FD, "<timeout>123</timeout>", strlen ("<timeout>123</timeout>"));
/* We just make a test. So don ' reboot system */
Write (FD, "<no_reboot>1</no_reboot>", strlen ("<no_reboot>1</no_reboot>"));
for (i=0; i<100; i++)
{
Write (FD, "1234", 4);
Usleep (1000000);
}
/* Attention:before Close FD, you should stop dog. Otherwise, it may still effects */
Write (FD, "<stop_dog>1</stop_dog>", strlen ("<stop_dog>1</stop_dog>"));
Close (FD);
return 0;
}
A software-implemented Linux watchdog-SOFT_WDT