gpt4 book ai didi

linux - 如何在我的 LKM 和 Linux 内核之间同步共享数据结构?

转载 作者:太空宇宙 更新时间:2023-11-04 10:43:35 26 4
gpt4 key购买 nike

我正在 Linux 中开发 LKM(可加载内核模块)。LKM想要的是通过TCB(即task_strct)遍历所有进程信息。

我想知道当 LKM 遍历数据结构时 TCB 数据结构是否正在更新。

也就是说,在LKM遍历TCB数据结构的过程中,数据结构可以因为进程的终止或创建而更新。我如何才能使我的 LKM 与不断更新 SMP 或非 SMP Linux 系统中的 TCB 数据结构的 Linux 内核同步?//道姆

最佳答案

I think you can traverse the process list via below sample code

struct task_struct *task;
rcu_read_lock();
for_each_process(task) {
task_lock(task);

/* do something with your task :) */

task_unlock(task);
}
rcu_read_unlock();

引用::how to iterate over PCB's to show information in a Linux Kernel Module?

关于linux - 如何在我的 LKM 和 Linux 内核之间同步共享数据结构?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34035444/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com