【问题标题】:How I can make synchronize between my LKM and the Linux kernel for shared data structure?如何在我的 LKM 和 Linux 内核之间进行同步以实现共享数据结构?
【发布时间】:2015-12-02 16:59:21
【问题描述】:

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

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

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

【问题讨论】:

  • 您应该检查是否存在互斥锁/锁以在互斥中访问此类信息。

标签: linux linux-kernel


【解决方案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?

【讨论】:

    猜你喜欢
    • 2013-07-04
    • 1970-01-01
    • 2014-07-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-29
    • 1970-01-01
    相关资源
    最近更新 更多