我有一個關於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',我只是不明白對沒有孩子/老兄弟的進程期望什麼。 –