Linux software watchdog watchdog use introduction _c language

Source: Internet
Author: User
Tags syslog

Background:

root@119.10.6.23:/usr/local/php# PS Aux|grep watchdog

Root 6 0.0 0.0 0 0? S Aug28 4:50 [watchdog/0]
Root 10 0.0 0.0 0 0? S Aug28 4:11 [WATCHDOG/1]
Root 14 0.0 0.0 0 0? S Aug28 3:58 [WATCHDOG/2]
Root 18 0.0 0.0 0 0? S Aug28 3:36 [WATCHDOG/3]

Report:

The simplest installation tutorial (CentOS)

Yum Install Watchdog-y
Modprobe Softdog
Chkconfig watchdog on
/etc/init.d/watchdog start

Configure the watchdog program to boot up and run automatically

chkconfig watchdog on

Start the watchdog.

sudo /etc/init.d/watchdog start

Linux has 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 user space by/dev/watchdog this character device. User space program once opened/dev/watchdog device (commonly known as "open the Dog"), will cause in the kernel to start a 1 minute timer (system default time), thereafter, the user space program needs to ensure that within 1 minutes to the device to write data (commonly known as "regular Feeding Dog"), Each write operation causes the timer to be reset. If the user space program is not written within 1 minutes, the timer expiration will result in a system reboot operation ("Dog bites man" hehe). 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 normal to "feed the Dog", the Linux system in the role of watchdog reboot (reboot), the core process is running again. More for embedded systems.

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));
	Syslog (log_warning, "FAILED to Open/dev/watchdog, errno:%d,%s", Err, strerror (err));

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

Feed the watchdog
if (fd_watchdog >= 0) {
	static unsigned char food = 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 not usually required to turn off the/dev/watchdog device:

close(fd_watchdog);

Required header file:

#include <unistd.h>
#include <sys/stat.h>
#include <syslog.h>
#include < Errno.h>

About Linux software watchdog watchdog is introduced here, what's the problem can leave a message

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.