某国中央银行在一台有 内存4T, 320个cpu核 的Linux服务器上跑一个数据库程序,数据库上存有他本国所有人民的银行账号信息,当此数据库程序在运行过程中,发生了IO读写错误,或者程序bug, 一下卡住了,那么他本国人民就都不能存钱取钱转账了,整个国民经济瞬间瘫痪。
本文转载自微信公众号「相遇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, “