我有一个关于task_struct列表的问题。内核task_struct和同级指针
/*
* pointers to (original) parent process, youngest child, younger sibling,
* older sibling, respectively. (p->father can be replaced with
* p->p_pptr->pid)
*/
task_t *p_opptr, *p_pptr, *p_cptr, *p_ysptr, *p_osptr;
我正在使用这些指针来运行进程的子进程。 我不明白(并且很难从内核代码中理解),如果最小的子列表结尾为null或是循环的?
我可以穿过所有p_cptr
,直到我达到NULL
,或者我应该再次回到头部吗?
谢谢。
内核链接列表是[圆形双向链表](http://en.wikipedia.org/wiki/Doubly_linked_list#Circular_doubly-linked_lists)。所以最后一个元素(尾部)指向第一个元素(头部)。看看[for_each_process()](http://lxr.free-electrons.com/source/include/linux/sched.h#L2529)宏。 –
无论你使用的是什么列表。所有列表在内核中都是循环的。它是通过列表函数实现来实现的:他们都在试图在每次操作后使列表循环。你需要为你的任务使用的是'list_for_each()'和'list_entry()'函数。详情请参阅[这个问题](http://stackoverflow.com/questions/8207160/kernel-how-to-iterate-the-children-of-the-current-process)。 –
我不是通过'list_head'指针迭代列表,而是直接通过'task_t'指针进行迭代。 没有'prev','next'我正在经历,所以它不是完全一样的情况。 我正在访问每个进程的'p_cptr'和'p_osptr',我只是不明白对没有孩子/老兄弟的进程期望什么。 –