WATCHDOG(4)
π WATCHDOG(4) β bestie's guide to the hardware + software watchdog πΆβ¨
okay so this is watchdog(4), from the Kernel Interfaces Manual, and it is literally the page you want if you've ever needed a thing that goes "hey. hey. you still alive?" to your kernel. it's giving guardian angel but make it a timer π«Ά
β¨ NAME β¨
watchdog β hardware and software watchdog π
πΈ SYNOPSIS πΈ
#include <sys/watchdog.h>
π DESCRIPTION π
so the watchdog facility is the whole system for controlling hardware and software watchdogs. that's the vibe, that's the whole point π
the device /dev/fido supports several optional ioctl(2) calls for configuration, and it responds to one operational ioctl(2) call, WDIOCPATPAT. that call takes a single argument β a timeout value specified as a power of two nanoseconds, or-ed with a flag that picks active or passive control of the watchdog. yes bestie, the timeout is in powers of two nanoseconds, do not question it, just respect it π
WD_ACTIVEmeans the watchdog will be kept from timing out from userland, for instance by thewatchdogd(8)daemon.WD_PASSIVEmeans the watchdog will be kept from timing out from the kernel.
the WDIOCPATPAT ioctl(2) call returns success if just one of the available watchdog(9) implementations supports setting the timeout to the specified timeout. meaning at least one watchdog is armed, periodt π₯ by default that'll 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. and if the call fails β for example if none of the watchdog(9) implementations support the timeout length β then all watchdogs are disabled and must be explicitly re-enabled. like, you gotta go turn them back on yourself, no auto-rescue, iykyk π
to disable the watchdogs, pass WD_TO_NEVER. and if disarming the watchdog(s) failed, an error is returned.
β οΈ real talk bestie: the watchdog might still be armed! do not assume it's off just because you asked nicely π
the optional configuration ioctl(2) commands are listed right here, along with the type of the parameter used. examples of their use can be found in watchdogd(8) π
WDIOC_SETTIMEOUTintβ set/reset the timerWDIOC_GETTIMEOUTintβ get total timeoutWDIOC_GETTIMELEFTintβ get time leftWDIOC_GETPRETIMEOUTintβ get the pre-timeoutWDIOC_SETPRETIMEOUTintβ set the pre-timeoutWDIOC_SETPRETIMEOUTACTintβ set the action when a pre-timeout occurs (seeWD_SOFT_*below)WDIOC_SETSOFTintβ use an internal software watchdog instead of hardware. there's also an external software watchdog, which is used by default if no hardware watchdog was attached.WDIOC_SETSOFTTIMEOUTACTintβ set the action when a soft timeout occurs
and these are the actions that may be specified for the pre-timeout or the internal software watchdog π multiple actions can be specified by ORing values together, slay:
WD_SOFT_PANICβ panicWD_SOFT_DDBβ enter debuggerWD_SOFT_LOGβlog(9)WD_SOFT_PRINTβprintf(9)
π¦ RETURN VALUES π¦
the WDIOCPATPAT ioctl(2) returns zero on success and non-zero on failure β¨
[EOPNOTSUPP]β no watchdog present in the kernel, or none of the watchdogs supports the requested timeout value (timeout value other than 0).[EOPNOTSUPP]β watchdog could not be disabled (timeout value of 0).[EINVAL]β invalid flag combination passed.
the configuration ioctl(2) operations return zero on success and non-zero on failure π
π§ EXAMPLES π§
#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);
this enables a watchdog to recover from a potentially freezing piece of code π₯ iconic behavior honestly
and then, in your kernel config:
options SW_WATCHDOG
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 πΈ
π SEE ALSO π
β HISTORY β
the watchdog code first appeared in FreeBSD 5.1 π
π AUTHORS π
the watchdog facility was written by Poul-Henning Kamp <phk@FreeBSD.org>. the software watchdog code and this manual page were written by Sean Kelly <smkelly@FreeBSD.org>. some contributions were made by Jeff Roberson <jeff@FreeBSD.org>. legends, all of them π«Ά
π BUGS π
the WD_PASSIVE option has not yet been implemented. we wait π―οΈπ
mwah, that's the whole page bestie β brought to you by Debian, dated January 2, 2018. go keep something alive out there ππΆβ¨
π¦ where this page comes from
- freebsd 15.1: base 15.1
- Copyright (c) 2004 Poul-Henning Kamp <phk@FreeBSD.org>
- Copyright (c) 2003, 2004 Sean M. Kelly <smkelly@FreeBSD.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms