【问题标题】:Linked List of Running Processes in Kernel 3.*内核 3.* 中正在运行的进程的链接列表
【发布时间】:2013-08-04 13:07:34
【问题描述】:

我想知道每个进程的下一个和上一个进程,它的状态是“TASK_RUNNING”。 在较旧的内核中,有一个 run_list 结构作为 task_struct 的成员。我怎样才能在内核 3 中做这样的事情?例如跟踪正在运行的进程列表,但我不知道内核 3 中将哪个结构定义为此类列表。

【问题讨论】:

    标签: process linux-kernel scheduling


    【解决方案1】:

    在较新的内核中,Linux 不会维护所有正在运行的进程的列表。相反,CFS 使用 sched_entity 的红黑树来存储有关正在运行的进程的信息。

    task_struct 包含 sched_entity 类型的成员 se。计划实体包含struct rb_node 类型的成员run_node。这就是你要找的。​​p>

    rbtree接口请咨询include/linux/rbtree.h。要从sched_entity 中提取task_struct,您可以使用container_of(your_se, struct task_struct, se);(请参阅kernel/sched/fair.c 中的task_of())。

    【讨论】:

    • 你的意思是我应该遍历rb tree作为正在运行的进程列表?
    • 是的。这就是我的意思。
    • 如果任务列表中的任务状态为 1(INTERRUPTABLE) ,它没有sched_entity?或者它有 sched_entity 但为空。
    • 'sched_entity` 被嵌入到task_struct 中,因此它在任何情况下都存在。如果任务没有运行,sched_entity 不会在 rbtree 中链接。所以,你不能遍历它。
    • 另一个问题:我在kernel/sched/fair.c 中看到了cfs_rq (runqueue)。它们包含sched_entities 中的sched_entities just ordered by priorities? and there's only one rbtree`,划分为多​​个运行队列?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-09
    • 2012-02-20
    • 2023-04-08
    相关资源
    最近更新 更多