Linux software watchdog watchdog--Open the door and put the dog, regularly feed the dog, the dog bites people

Source: Internet
Author: User

Linux comes with a watchdog implementation that monitors the operation of the system, including a kernel watchdog module and a user-space watchdog program.

The kernel watchdog module communicates with the user space by/dev/watchdog this character device. User space program once opened/dev/watchdog device (commonly known as " Open the Dog "), will cause a 1-minute timer in the kernel (system default time), after that, the user space program needs to ensure in 1 minutes to the device to write data (commonly known as " Regularly feed the Dog "), each write operation will cause the timer to be reset. If the user-space program does not write within 1 minutes, the timer expires causing a system reboot operation (commonly known as " Dog Bites "). Through this mechanism, we can ensure that the core process of the system is running for most of the time, even if the process crashes in a particular situation, because it is not possible to "feed the dog" at regular intervals, and the Linux system restarts (reboot) under the watchdog function, the core process is running again. More for embedded systems.

The user space program can stop the timer in the kernel by turning off/dev/watchdog.

Turn on the/dev/watchdog device (" Open the Dog "):

int fd_watchdog = open ("/dev/watchdog", o_wronly); if (Fd_watchdog = =-1)    {int err = errno;    printf ("\ n!!! FAILED to Open/dev/watchdog, errno:%d,%s\n", Err, strerror (err));     " FAILED to Open/dev/watchdog, errno:%d,%s " , err, strerror (err));}

Write data to the/dev/watchdog device at regular intervals (" feed the Dog regularly "):

//Feed the watchdogif(Fd_watchdog >=0) {    StaticUnsignedCharFood =0; ssize_t eaten= Write (Fd_watchdog, &food,1); if(Eaten! =1) {puts ("\ n!!! FAILED feeding watchdog"); Syslog (log_warning,"FAILED feeding watchdog"); }}

This step is usually not required to turn off the/dev/watchdog device:

"Reprint" http://blog.csdn.net/liigo/article/details/9227205

Http://www.oschina.net/p/watchdog

Linux software watchdog watchdog--Open the door and put the dog, regularly feed the dog, the dog bites people

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.