在Linux内核中遍历task_struct-> children [英] traversing task_struct->children in linux kernel

查看:449
本文介绍了在Linux内核中遍历task_struct-> children的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图遍历linux内核中task_struct的子级,并从这些级中获取信息.我在所有信息方面都遇到了问题,因此让我们在获取pid的过程中保持简单性即可.

I am trying to traverse a task_struct's children in the linux kernel and get information from the children. I'm having problems with all the information, so let's just keep it at the getting the pid for simplicity.

这是我代码的相关部分.

This is the relavant part of my code.

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);
}

我认为问题出在list_entry上,但我不知道如何解决它,我发现的所有示例似乎都以相同的方式调用它.

I think the problem is with list_entry but I don't know how to fix it, all the examples I can find seem to be calling it the same way.

这应该打印出所有子PID,但我总是得到相同的数字-17....它的顺序为10 ^ 9或10 ^ 11.

This should print out all the child PIDs, instead I always get the same number -17.... it's on the order of 10^9 or 10^11.

有人可以帮我吗?编译大约需要30分钟,因此,尝试记录其他内容并不是真正的选择.

can anyone help me out here? compiling takes about 30 minutes, so trying a log of different things isn't really an option.

推荐答案

您应该使用

list_entry(p, struct task_struct, sibling);

不是

list_entry(p, struct task_struct, children);

还有,当您经过孩子们时,您应该锁定tasklist_lock.

Ho and also, you should lock the tasklist_lock when you go through the childrens.

这篇关于在Linux内核中遍历task_struct-> children的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆