tail head cat sleep
QR code linking to this page

Manual Pages  — WATCHDOG


watchdog – hardware and software watchdog



#include <sys/watchdog.h>


The watchdog facility is used for controlling hardware and software watchdogs.

The device /dev/fido supports several optional ioctl(2) calls for configuration, and responds to a single operational ioctl call, WDIOCPATPAT. It takes a single argument which represents a timeout value specified as a power of two nanoseconds, or-ed with a flag selecting active or passive control of the watchdog.

WD_ACTIVE indicates that the watchdog will be kept from timing out from userland, for instance by the watchdogd(8) daemon. WD_PASSIVE indicates that the watchdog will be kept from timing out from the kernel.

The WDIOCPATPAT ioctl(2) call will return success if just one of the available watchdog(9) implementations supports setting the timeout to the specified timeout. This means that at least one watchdog is armed. By default, this will be a hardware watchdog if one is present, but if no hardware watchdog is able to process the request, a default software watchdog is enabled. If the call fails, for instance if none of watchdog(9) implementations support the timeout length, all watchdogs are disabled and must be explicitly re-enabled.

To disable the watchdogs pass WD_TO_NEVER. If disarming the watchdog(s) failed an error is returned. The watchdog might still be armed!

The optional configuration ioctl commands are listed here, along with the type of the parameter used. Examples of their use can be found in watchdogd(8).
  set/reset the timer
  get total timeout
  get time left
  get the pre-timeout
  set the pre-timeout
  Set the action when a pre-timeout occurs (see WD_SOFT_* below).
  Use an internal software watchdog instead of hardware. There is also an external software watchdog, which is used by default if no hardware watchdog was attached.
  Set the action whan a soft timeout occurs.

The actions that may be specified for the pre-timeout or the internal software watchdog are listed here. Multiple actions can be specified by ORing values together.
WD_SOFT_DDB enter debugger
WD_SOFT_LOG log(9)


The WDIOCPATPAT ioctl returns zero on success and non-zero on failure.
  No watchdog present in the kernel or none of the watchdogs supports the requested timeout value (timeout value other than 0).
  Watchdog could not be disabled (timeout value of 0).
  Invalid flag combination passed.

The configuration ioctl operations return zero on success and non-zero on failure.


#include <paths.h>
#include <sys/watchdog.h>

#define WDPATH  "/dev/" _PATH_WATCHDOG int wdfd = -1;

static void wd_init(void) {         wdfd = open(WDPATH, O_RDWR);         if (wdfd == -1)                 err(1, WDPATH); } static void wd_reset(u_int timeout) {         if (ioctl(wdfd, WDIOCPATPAT, &timeout) == -1)                 err(1, "WDIOCPATPAT"); }

/* in main() */ wd_init(); wd_reset(WD_ACTIVE|WD_TO_8SEC); /* potential freeze point */ wd_reset(WD_TO_NEVER);

Enables a watchdog to recover from a potentially freezing piece of code.

    options SW_WATCHDOG

in your kernel config forces a software watchdog in the kernel to be configured even if a hardware watchdog is configured, dropping to KDB or panicking when firing, depending on the KDB and KDB_UNATTENDED kernel configuration options.


watchdogd(8), watchdog(9)


The watchdog code first appeared in FreeBSD 5.1 .


The watchdog facility was written by Poul-Henning Kamp <Mt phk@FreeBSD.org>. The software watchdog code and this manual page were written by Sean Kelly <Mt smkelly@FreeBSD.org>. Some contributions were made by Jeff Roberson <Mt jeff@FreeBSD.org>.


The WD_PASSIVE option has not yet been implemented.

WATCHDOG (4) January 2, 2018

tail head cat sleep
QR code linking to this page

Please direct any comments about this manual page service to Ben Bullock. Privacy policy.