c - 如何在不冻结系统的情况下处理长中断
问题描述
我正在实现一个中断处理,它可以从 Linux 内核模块关闭一个打开的 txt 文件。我能够获得 txt 文件路径(见图)。但是,当我尝试关闭该文件时,我的计算机总是死机。我使用 close_fd() 但它不起作用 来自 dmesg 的结果,在 pid 10367 中检测到一个 txt 文件 这是我的代码:
for_each_process(task_list) {
pr_info("Process: %s\t PID:[%d]\t State:%s\n",
task_list->comm, task_list->pid,
get_task_state(task_list->state));
if (task_list->files == NULL) continue; // Ignore processes without files
fdt = files_fdtable(task_list->files);
int i=0;
while(fdt->fd[i] != NULL) {
files_path = fdt->fd[i]->f_path;
mode_path = fdt->fd[i]->f_mode;
cwd = d_path(&files_path,buf,100*sizeof(char));
printk(KERN_INFO "Open file with fd %d %s mode: %d", i,cwd, mode_path);
//Suppose that I can detect a txt file is running in pid 10367. And I want to safety close it
if (task_list->pid == 10367){
printk(KERN_INFO "This below function does not work");
close_fd(fdt->fd[i]);
}
i++;
}
}
我不知道我犯了哪些错误。有人可以评论和支持我吗?此致
解决方案
我终于找到了解决方案。这是filp_close()
flush_cache_all() ;
close_result = filp_close(fdt->fd[i], NULL);
整个系统不会被冻结。非常感谢您的建议。问候
推荐阅读
- dataset - 如何使用 TF 2.0 从海量二进制数据中生成训练数据集?
- java - 如何判断一个类是否存在于项目中
- doxygen - 我可以生成将出现在 doxygen 报告中的常规文档吗?
- mysql - 为什么我会收到错误 1054:某些输入的字段列表中的未知列?
- php - 获取邮件正文的数据:phpmailer
- angular - Angular 7:使用异步管道过滤多个键的搜索结果
- azure-active-directory - 在 Microsoft OpenId Connect / Azure AD 中自定义登录页面
- python - Python Beautiful Soup 使用类解析表
- php - PHP 在 Visual Studio Code 中无法正常运行
- r - 使用 Caret 查找重要的特征