dev*_*vin 4 linked-list linux-kernel
我试图遍历linux内核中的task_struct的子节点并从子节点获取信息.我遇到了所有信息的问题,所以让我们保持简单的pid.
这是我的代码的相关部分.
struct list_head * p;
struct task_struct ts, *tsk;
pid_t tmp_pid;
INIT_LIST_HEAD(&ts.children);
current = tsk;
list_for_each(p, &(tsk->children)){
ts = *list_entry(p, struct task_struct, children);
tmp_pid = ts.pid;
printk("the pid is %d\n", tmp_pid);
}
Run Code Online (Sandbox Code Playgroud)
我认为问题在于list_entry但我不知道如何解决它,我能找到的所有例子似乎都是以同样的方式调用它.
这应该打印出所有子PID,而不是我总是得到相同的数字-17 ....它是10 ^ 9或10 ^ 11的数量级.
有人可以帮我从这里出去吗?编译大约需要30分钟,所以尝试记录不同的东西并不是一个真正的选择.
你应该使用
list_entry(p, struct task_struct, sibling);
Run Code Online (Sandbox Code Playgroud)
不
list_entry(p, struct task_struct, children);
Run Code Online (Sandbox Code Playgroud)
何而且,当你经过孩子们时,你应该锁定tasklist_lock.