kernel中遍历所有进程

看下具体的宏定义实现:

#define for_each_process(p) \
	for (p = &init_task ; (p = next_task(p)) != &init_task ; )


在看下具体例子,打印所有进程的函数调用栈:

static void wdt_report_info (void)
{
    struct task_struct *task ;
    task = &init_task ;
    
    printk ("Qwdt: -- watchdog time out\n") ;
    for_each_process (task)
    {
        if (task->state == 0)
        {
            printk ("PID: %d, name: %s\n backtrace:\n", task->pid, task->comm) ;
            show_stack (task, NULL) ;
            printk ("\n") ;
        }
    }
    printk ("backtrace of current task:\n") ;
    show_stack (NULL, NULL) ;
 }


 

你可能感兴趣的:(kernel,栈,遍历所有进程)