Linux Watchdog Timer: Automatic Reboot on System Hang

In the Linux operating system, high availability and fault recovery are managed through watchdog timers that automatically reboot the system during a complete freeze or kernel lockup. This mechanism relies on a continuous heartbeat system: an active timer counts down toward zero, requiring the operating system or a dedicated user-space daemon to periodically "pet" or reset the counter. If the operating system hangs, becomes deadlocked, or crashes, the counter reaches zero and triggers a hardware or software reset, returning the machine to an operational state without manual intervention.

The Watchdog Mechanism

The core operation of a Linux watchdog relies on a simple countdown timer. Under normal operating conditions, a process regularly writes to the watchdog device to reset the expiration timer—an action commonly referred to as "pinging," "kicking," or "petting" the dog.

When a critical failure occurs, such as a kernel panic, out-of-memory deadlock, or hard CPU lockup, the running processes are halted. Consequently, the reset signal is never delivered. Once the countdown expires (typically after a user-defined threshold, such as 30 or 60 seconds), the watchdog hardware asserts the system's reset line, simulating a physical push of the power or reset button.

Hardware vs. Software Watchdogs

Linux supports both hardware-based and software-emulated watchdog solutions:

The Linux Kernel Watchdog Subsystem

The Linux kernel standardizes watchdog management through its core driver framework located in drivers/watchdog/. The system exposes these devices to user space through special character devices, primarily /dev/watchdog (legacy single-open interface) and /dev/watchdog0 (supporting modern sysfs attributes).

Key driver behaviors include:

User-Space Integration

The kernel provides the interface, but user-space software typically manages the heartbeat logic:

NMI Watchdogs for Lockup Detection

For multi-core systems, Linux includes an internal NMI (Non-Maskable Interrupt) watchdog managed by the kernel. It couples high-resolution performance counters with NMIs to detect when a single CPU core is stuck inside an interrupt handler or spinlock for more than a set duration (typically 10 to 20 seconds). When combined with the sysctl setting kernel.panic_on_io_nmi = 1 or kernel.panic = 10, the kernel will detect the stuck core, induce a panic, and automatically reboot the machine after 10 seconds.