文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>在Linux内核中遍历当前进程的方法

在Linux内核中遍历当前进程的方法

时间:2009-03-02  来源:chinaunix_lb

Linux内核中,进程描述符关于当前进程集合的定义如下: struct task_struct {       volatile long state; 当前进程状态     ....     struct list_head tasks; } list_head的定义如下: struct list_head {       struct list_head *next,*prev; } 下面来看一下具体的过程: struct task_struct *p = current; //current是内核中指向当前task的指针 由此我们可以通过 p->task.next或是p->task.prev来遍历list_head。 如何从list_head再获得task_struct的指针,需要list_entry()函数来处理。   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)   通过这种方式实现对当前进程的遍历。        
相关阅读 更多 +
排行榜 更多 +
爱是小事最新版

爱是小事最新版

休闲益智 下载
悬案2刹那惊颤游戏

悬案2刹那惊颤游戏

冒险解谜 下载
几何飞行内购修改版

几何飞行内购修改版

飞行射击 下载