1. Get information about soft dog in the system
# Modinfo Softdog
FileName:/lib/modules/3.2.0-4-686-pae/kernel/drivers/watchdog/softdog.ko
2. Loading the module
# Insmod/lib/modules/3.2.0-4-686-pae/kernel/drivers/watchdog/softdog.ko
3./dev/watchdog now visible, or create
# Mknod/dev/watchdog C 10 130
4. View Dev and give permissions
# ls-l/dev/watchdog
CRW-------1 root root, Mar 16:27/dev/watchdog
# chmod O+rw/dev/watchdog
5. Test using Watch Dog
Simple can be written as:
# echo 0 >/dev/watchdog//Time from now on, enable watchdog
# echo-n V >/dev/watchdog//Deactivate watchdog
6. the difference between hardware and software watchdog
Hardware watchdog must have hardware circuit support, device node/dev/watchdog corresponding to the real physical equipment, different types of hardware watchdog devices by the corresponding hardware-driven management. Software watchdog by a kernel module Softdog.ko through the timer mechanism,/dev/watchdog does not correspond to the real physical device, just for the application to provide an interface with the operation of the hardware watchdog.
Hardware watchdog is more reliable than software watchdog. The software watchdog the kernel-based timer, and the software watchdog will fail when the kernel or interrupt is abnormal. The hardware watchdog is controlled by its own hardware circuit, which is independent of the kernel. The hardware watchdog does not perform a write operation within the set time interval regardless of the current system state, and the system will still restart
The watchdog is a hybrid device, so the main device number is 10,/include/linux/miscdevice.h defined in his secondary device number of 130
1#include <stdio.h>2#include <stdlib.h>3#include <unistd.h>4 5#include <sys/types.h>6#include <sys/stat.h>7#include <fcntl.h>8#include <termios.h>9#include <errno.h>Ten#include <signal.h> One#include <time.h> A#include <pthread.h> -#include <sys/time.h> -#include <linux/watchdog.h> the#include <sys/ioctl.h> - - time_t backtime; - structTM *Pbacktime; + intwt_fd; - + Static voidSigalarm (intSig) A { at CharFlag ='0'; -(void) Time (&backtime); -Pbacktime= localtime (&backtime); -printf"Day :%d; hour:%d; min:%d; SEC:%d\n", Pbacktime->tm_mday, Pbacktime->tm_hour, Pbacktime->tm_min, pbacktime->tm_sec); - -Write (WT_FD, &flag,1);//Reset Watchdog Feed the dog inAlarm2); - return; to } + - the intMain () * { $ CharFlag ='V';Panax Notoginseng intret; - intTimeout = the; the + if(Sig_err = =signal (SIGALRM, sigalarm)) A { thePerror ("Signal (sigalarm) Error"); + } - $WT_FD = open ("/dev/watchdog", O_RDWR); $ if(WT_FD <=0) - { -printf"Fail to open watchdog device!\n"); the } - ElseWuyi { theWrite (Wt_fd,null,0); -printf"Turn on Watch dog\n"); WuRET = IOCTL (WT_FD, Wdioc_settimeout, &timeout); - if(EINVAL = =ret) About { $printf"EINVAL returned\n"); - } - Else if(Efault = =ret) - { Aprintf"efault returned\n"); + } the Else if(0==ret) - { $printf"Set Timeout%d secs success\n", timeout); the } the Else the { theprintf"Ret%d\n", ret); - } in } the theAlarm3); About the while(1); the theWrite (WT_FD, &flag,1); +printf"turned off Watch dog\n"); - Close (WT_FD); the return 0;Bayi}
View Code
WebRTC & Libjingle
Http://blog.sina.com.cn/s/blog_69a04cf401016gz4.html
Watchdog enable and Test & WebRTC