我正在 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/