linux-kernel – 在linux内核中遍历task_struct-> children
发布时间:2020-12-14 00:54:49 所属栏目:Linux 来源:网络整理
导读:我试图遍历 linux内核中的task_struct的子节点并从子节点获取信息.我遇到了所有信息的问题,所以让我们保持简单的pid. 这是我的代码的相关部分. struct list_head * p;struct task_struct ts,*tsk;pid_t tmp_pid;INIT_LIST_HEAD(ts.children);current = tsk;l
我试图遍历
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 %dn",tmp_pid); } 我认为问题在于list_entry但我不知道如何解决它,我能找到的所有例子似乎都是以同样的方式调用它. 这应该打印出所有子PID,而不是我总是得到相同的数字-17 ….它是10 ^ 9或10 ^ 11的数量级. 有人可以帮我从这里出去吗?编译大约需要30分钟,所以尝试记录不同的东西并不是一个真正的选择. 解决方法
你应该使用
list_entry(p,sibling); 不 list_entry(p,children); 何而且,当你经过孩子们时,你应该锁定tasklist_lock. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |