Linux 內建了一個 watchdog 的實現,用於監視系統的運行,包括一個核心 watchdog module 和一個使用者空間的 watchdog 程式
核心 watchdog 模組:
核心 watchdog 模組通過 /dev/watchdog 這個字元裝置與使用者空間通訊。使用者空間程式一旦開啟 /dev/watchdog 裝置,就會導致在核心中啟動一個 1分鐘的定時器,此後,使用者空間程式需要保證在 1分鐘之內向這個裝置寫入資料,每次寫操作會導致重新設定定時器。如果使用者空間程式在 1分鐘之內沒有寫操作,定時器到期會導致一次系統 reboot 操作。
使用者空間程式可通過關閉 /dev/watchdog 來停止核心中的定時器。
使用者空間的 watchdog 守護進程:
在使用者空間,還有一個叫做 watchdog 的守護進程,它可以定期對系統進行檢測,包括:
- Is the process table full?
- Is there enough free memory?
- Are some files accessible?
- Have some files changed within a given interval?
- Is the average work load too high?
- Has a file table overflow occurred?
- Is a process still running? The process is specified by a pid file.
- Do some IP addresses answer to ping?
- Do network interfaces receive traffic?
- Is the temperature too high? (Temperature data not always available.)
- Execute a user defined command to do arbitrary tests.
如果某項檢測失敗,則可能導致一次 soft reboot (類比一次 shutdown 命令的執行)
它還可以通過 /dev/watchdog 來觸發核心 watchdog 的運行。