我知道如何创建内核并通过简单包含linux/sched.h
并使用以下代码线性迭代进程:
struct task_struct *task;
for_each_process(task)
{
printk("Name: %s PID: [%d]\n", task->comm, task->pid);
}
如何使用深度优先搜索打印这些任务?我希望输出结果类似于ps -eLf
的输出。
以下代码片段仅供参考:
struct task_struct *task;
struct list_head *list;
list_for_each(list, &init_task->children) {
task = list_entry(list, struct task_struct, sibling);
/* task points to the next child in the list */
}
我知道task->comm
返回任务的名称,task->pid
返回该任务的PID。
用于状态和父PID的字段是什么?