内核:如何迭代当前进程的子进程?

zer*_*lus 6 c linux-kernel

在Linux Kernel Development,第3版中,这段代码用于遍历当前进程的子代.

list_for_each(list, &current->children) {
    task = list_entry(list, struct task_struct, sibling);
    /* task now points to one of current’s children */
}
Run Code Online (Sandbox Code Playgroud)

这个成语中的"兄弟姐妹"看起来不合时宜.它的目的是什么?

caf*_*caf 9

sibling是与父项子项列表对应的list_head结构名称struct task_struct.

也就是说,在此循环中list始终指向a的sibling成员struct task_structchildren父成员.