本文转载自微信公众号「相遇Linux」,可以通过以下二维码关注。转载本文请联系相遇Linux公众号。
在Linux内核中有三个watchdog(看门狗),它们都需要被悉心的喂养照料,分别是:
1. /dev/watchdog
2.softlockup检测机制
3.hardlockup检测机制
首先看 1./dev/watchdog,此看门狗该怎样喂养呢,linux内核中有一段样例代码:
- samples/watchdog/watchdog-simple.c
- // SPDX-License-Identifier: GPL-2.0
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <fcntl.h>
- int main(void)
- {
- int fd = open(“/dev/watchdog”, O_WRONLY);
- int ret = 0;
- if (fd == -1) {
- perror(“watchdog”);
- exit(EXIT_FAILURE);
- }
- while (1) {
- ret = write(fd, “