Process 需要澄清Robert Love在Linux内核中给出的内容吗

Process 需要澄清Robert Love在Linux内核中给出的内容吗,process,linux-kernel,Process,Linux Kernel,我是LKD的新手,我正在读罗伯特·洛夫的书。我坚持理解一个概念如下 类似地,可以使用 struct task_struct *task; struct list_head *list; list_for_each(list, &current->children) { task = list_entry(list, struct task_struct, sibling); /* task now points to one of current’s childre

我是LKD的新手,我正在读罗伯特·洛夫的书。我坚持理解一个概念如下

类似地,可以使用

struct task_struct *task;
struct list_head *list;
list_for_each(list, &current->children) {
    task = list_entry(list, struct task_struct, sibling);
    /* task now points to one of current’s children */
}
如果有人能解释一下列表,我也会很高兴的


我很难理解上面的代码片段,特别是
list\u for_each
的工作原理。

list\u for_each
是一个宏

由于C中的宏是通过文本替换进行扩展的,因此您引用的代码片段变成

for (list = (&current->children)->next; list != (&current->children); list = list->next) {
    task = list_entry(list, struct task_struct, sibling);
    /* task now points to one of current’s children */
}

这段代码从节点
(¤t->children)->next
开始遍历一个循环链表,直到返回到
(¤t->children)->next
,你试过了吗?@larsmans是的,我也试过,但仍然没有得到它。
for (list = (&current->children)->next; list != (&current->children); list = list->next) {
    task = list_entry(list, struct task_struct, sibling);
    /* task now points to one of current’s children */
}