【发布时间】:2015-09-16 13:05:57
【问题描述】:
我想打印每个进程的信息以及该进程在运行时正在做什么。即该进程连续读取/写入哪个文件。
为此,我正在编写一个内核模块。
任何人都知道如何在内核模块中访问此信息或如何访问我的内核模块中的进程表数据结构?
任务的伪代码如下:
1. get each process from /proc.
2. Access the data structure of that process i.e. process table and all
3. print what that process is doing i.e. which file it is accessing (i.e. reading or writing) at rutime.
【问题讨论】:
-
你不能使用current宏吗?
-
请看看我刚才添加的伪代码有问题。我猜“当前”将提供对当前流程数据结构的访问权限。
-
请看下面答案中的示例是否满足用例,我认为可以。
-
是的,但是如果我想访问其他进程数据结构,它会起作用吗?虽然我会尝试那个例子。
-
当前宏查看当前进程的内核栈地址,然后切断最后 13 位以获得 PCB(进程的 task_struct)地址,因为它们都“活”在同一个 8K 中.其他进程的 task_structs 是可访问的,例如按 PID(请参阅 this question and answer)。
标签: linux-kernel kernel kernel-module