---
name: "SW_WATCHDOG"
section: "4"
platform: "freebsd"
package: "base"
version: "16.0-CURRENT-20261027-61c70dc16a79"
release: "FreeBSD 16.0-CURRENT (2026-10-27)"
platforms: ["freebsd"]
url: "https://new.carta.tech/SW_WATCHDOG"
---

# SW\_WATCHDOG(4)

hardware and software watchdog

## NAME

**watchdog** – hardware and software watchdog

## SYNOPSIS

**#include \<sys/watchdog.h\>**

## DESCRIPTION

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

The device */dev/fido* supports several optional [ioctl(2)](/ioctl/2.md) calls for configuration, and responds to a set of operational [ioctl(2)](/ioctl/2.md) calls:

- WDIOCPATPAT

  Pat the watchdog.

- WDIOC\_CONTROL

  Enable, disable, or reset the watchdog.

The WDIOCPATPAT [ioctl(2)](/ioctl/2.md) call takes a single argument which represents a timeout value specified as a *sbintime\_t* of the timeout period for the watchdog.

The WDIOCPATPAT [ioctl(2)](/ioctl/2.md) call will return success if just one of the available [watchdog(9)](/watchdog/9.md) 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)](/watchdog/9.md) implementations support the timeout length, all watchdogs are disabled and must be explicitly re-enabled.

To disable the watchdogs use the WDIOC\_CONTROL [ioctl(2)](/ioctl/2.md) call with the WD\_CTRL\_DISABLE flag. If disarming the watchdog(s) failed an error is returned. The watchdog might still be armed! To reenable the watchdogs use the WDIOC\_CONTROL [ioctl(2)](/ioctl/2.md) call with the WD\_CTRL\_ENABLE flag. Another way to pat the watchdog is with the WDIOC\_CONTROL [ioctl(2)](/ioctl/2.md) call passing the WDIOC\_CTRL\_RESET flag.

The optional configuration [ioctl(2)](/ioctl/2.md) commands are listed here, along with the type of the parameter used. Examples of their use can be found in [watchdogd(8)](/watchdogd/8.md).

- WDIOC\_SETTIMEOUT *sbintime\_t*

  set/reset the timer

- WDIOC\_GETTIMEOUT *sbintime\_t*

  get total timeout

- WDIOC\_GETTIMELEFT *sbintime\_t*

  get time left

- WDIOC\_GETPRETIMEOUT *sbintime\_t*

  get the pre-timeout

- WDIOC\_SETPRETIMEOUT *sbintime\_t*

  set the pre-timeout

- WDIOC\_SETPRETIMEOUTACT *int*

  Set the action when a pre-timeout occurs (see WD\_SOFT\_\* below).

- WDIOC\_SETSOFT *int*

  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.

- WDIOC\_SETSOFTTIMEOUTACT *int*

  Set the action when 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\_PANIC

  panic

- WD\_SOFT\_DDB

  enter debugger

- WD\_SOFT\_LOG

  [log(9)](/log/9.md)

- WD\_SOFT\_PRINT

  [printf(9)](/printf/9.md)

## RETURN VALUES

The WDIOCPATPAT [ioctl(2)](/ioctl/2.md) 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)](/ioctl/2.md) 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);
```

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.

## SEE ALSO

[watchdogd(8)](/watchdogd/8.md), [watchdog(9)](/watchdog/9.md)

## 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*⟩.

## BUGS

The WD\_PASSIVE option has not yet been implemented.
