- 論壇徽章:
- 0
|
Linux內(nèi)核中,進程描述符關(guān)于當前進程集合的定義如下:
struct task_struct {
volatile long state; 當前進程狀態(tài)
....
struct list_head tasks;
}
list_head的定義如下:
struct list_head {
struct list_head *next,*prev;
}
下面來看一下具體的過程:
struct task_struct *p = current; //current是內(nèi)核中指向當前task的指針
由此我們可以通過 p->task.next或是p->task.prev來遍歷list_head。
如何從list_head再獲得task_struct的指針,需要list_entry()函數(shù)來處理。
list_entry的定義
/**
*list_entry get the struct of this entry
*ptr: the struct list_head pointer
*type: the type of the struct this is embedded in
*member: the name of the list_struct within the struct
*/
#define list_entry(ptr,type,member) container_of(ptr,type,member)
使用方式如下:
list_entry((p)->tasks.next,struct task_struct,tasks)
通過這種方式實現(xiàn)對當前進程的遍歷。
本文來自ChinaUnix博客,如果查看原文請點:http://blog.chinaunix.net/u2/83134/showart_1848440.html |
|