我正在Linux中开发LKM(可加载内核模块)。 LKM想要的是通过TCB(即task_strct)遍历所有过程信息。
我想知道在LKM遍历数据结构时TCB数据结构是否正在更新。
也就是说,在LKM遍历TCB数据结构期间,由于进程终止或创建,数据结构可以更新。 如何在LKM和Linux内核之间进行同步,以便在SMP或非SMP Linux系统中不断更新TCB数据结构? // Daum的
答案 0 :(得分:1)
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?