2021-12-10 Linux内核中watchdog,用户层喂狗程序分析
一、我这里是MTK平台,喂狗的代码在\system\core\watchdogd\,实际测试,如果write(fd, "", 1);注释掉,开机后过段时间会reboot。
1、\system\core\watchdogd\watchdogd.cpp
/** Copyright (C) 2012 The Android Open Source Project** Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at** http://www.apache.org/licenses/LICENSE-2.0** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* See the License for the specific language governing permissions and* limitations under the License.*/#include <errno.h>
#include <fcntl.h>
#include <linux/watchdog.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>#include <android-base/logging.h>#define DEV_NAME "/dev/watchdog"int main(int argc, char** argv) {android::base::InitLogging(argv, &android::base::KernelLogger);int interval = 10;if (argc >= 2) interval = atoi(argv[1]);int margin = 10;if (argc >= 3) margin = atoi(argv[2]);LOG(INFO) << "watchdogd started (interval " << interval << ", margin " << margin << ")!";int fd = open(DEV_NAME, O_RDWR | O_CLOEXEC);if (fd == -1) {PLOG(ERROR) << "Failed to open " << DEV_NAME;return 1;}int timeout = 118;//interval + margin;int ret = ioctl(fd, WDIOC_SETTIMEOUT, &timeout);if (ret) {PLOG(ERROR) << "Failed to set timeout to " << timeout;ret = ioctl(fd, WDIOC_GETTIMEOUT, &timeout);if (ret) {PLOG(ERROR) << "Failed to get timeout";} else {if (timeout > margin) {interval = timeout - margin;} else {interval = 1;}LOG(WARNING) << "Adjusted interval to timeout returned by driver: "<< "timeout " << timeout << ", interval " << interval << ", margin "<< margin;}}while (true) {write(fd, "", 1);PLOG(INFO) << "no write to fd INFO 119 " << DEV_NAME;PLOG(ERROR) << "write to fd ERROR " << DEV_NAME;sleep(interval);}
}
2、Android.bp
cc_binary {name: "watchdogd",recovery_available: true,srcs: ["watchdogd.cpp"],cflags: ["-Wall","-Wextra","-Werror",],shared_libs: ["libbase"],sanitize: {misc_undefined: ["signed-integer-overflow"],},
}
二、查看该进程。
三、查看kernel的log
2021-12-10 Linux内核中watchdog,用户层喂狗程序分析相关推荐
- linux内核中watchdog、lockup、stall、hung等检测
目录 lockup 一.watchdog看门狗 二.soft /hard lockup 1.soft lockup 2.hard lockup 三.kernel's hung task 四.work ...
- Linux内核出错的栈打印详解,linux内核中打印栈回溯信息 - dump_stack()函数分析
简介 当内核出现比较严重的错误时,例如发生Oops错误或者内核认为系统运行状态异常,内核就会打印出当前进程的栈回溯信息,其中包含当前执行代码的位置以及相邻的指令.产生错误的原因.关键寄存器的值以及函数 ...
- 【Linux 内核】进程管理 ( 进程特殊形式 | 内核线程 | 用户线程 | C 标准库与 Linux 内核中进程相关概念 | Linux 查看进程命令及输出字段解析 )
文章目录 一.进程特殊形式 ( 内核线程 | 用户线程 ) 二.C 标准库与 Linux 内核中进程相关概念 三.Linux 查看进程命令及输出字段解析 一.进程特殊形式 ( 内核线程 | 用户线程 ...
- Linux内核中的Watchdog
linux内核中有多个watchdog,他们属于不同模块,可同时存在. 用户态watchdog 可以在用户态程序操作,设置超时时间喂狗时间 .(只是通过内核提供的接口操作) 1./dev/watchd ...
- linux 内核信号量与用户态信号量(system v,信号量在Linux多线程机制中的应用
[摘 要]本文以信号量原理为基础,重点阐述信号量在Linux多线程同步机制中的实现特色. [关键词]信号量:Linux:多线程:同步 1 信号量 1965年E. W. Dijkstra首次提出信号量的 ...
- 什么是Linux系统调用system call?(Linux内核中设置的一组用于实现各种系统功能的子程序)(区别于标准C库函数调用)核心态和用户态的概念、中断的概念、系统调用号、系统调用表
文章目录 什么是系统调用? 为什么要用系统调用? 系统调用是怎么工作的? 如何使用系统调用? _syscall*()是什么? errno是什么? 调用性能问题 Linux系统调用列表 进程控制 文件系 ...
- Linux 之父 LinusTorvalds 喊话:Rust 即将出现在 Linux 内核中
上个月,Linus Torvalds 本人在 Linux 基金会开源峰会上发言称,Rust 有可能很快就会出现在 Linux 的内核中,最快是下一个内核周期. Linus Torvalds 和 Dir ...
- Linux 内核中的宏定义
Linux 内核中的宏定义 rtoax 日期 内核版本:linux-5.10.13 注释版代码:https://github.com/Rtoax/linux-5.10.13 __attribute__ ...
- Linux 内核中的数据结构:双链表,基数树,位图
Linux 内核中的数据结构 rtoax 2021年3月 1. 双向链表 Linux 内核自己实现了双向链表,可以在 include/linux/list.h 找到定义.我们将会从双向链表数据结构开始 ...
最新文章
- 关于Cloud各种组件的停更/升级/替换
- 多个ip对应的是同一个mac_Python3+Scapy安装使用 + 查询本机对应网卡,IP,MAC代码...
- javascript 嵌入python_通过Python将区块链数据嵌入Javascript,这是正确的方法吗?
- java build返回空值_OKHTTP拦截器不断返回空值并使应用程序崩溃
- boolean android.content.SharedPreferences.getBoolean(String key, boolean defValue)
- Whitted光线追踪实现
- elementui表格宽度适应内容_element ui 表格高度自适应
- 『商务口语』2010.01.11--你要在这里停留多久?
- 历史学与计算机科学交叉学科,药学与其他学科的交叉学科有哪些?需要学习什么课..._药学职称考试_帮考网...
- 南阳理工acm449 不再爱你……
- python实现bt下载器_Python 实现自动获取种子磁力链接方式
- 计算机网络16进制地址,计算机内存地址和为什么用16进制?
- JS中点语法和中括号语法区别
- 虚幻C++入门个人笔记(2)——标记宏、结构体枚举、资源加载、代理
- nodejs 系统 临时文件夹
- 【搬运】1 简谱和基本知识
- 『dos』使用bat文件打开jupyter lab
- 对于互联网现状的认知与感悟
- 哪种耳机适合跑步用、跑步运动耳机推荐
- Linux使用scp命令远程复制/上传文件