我想迭代内核中的所有任务(线程和进程)并使用 for_each_process 宏打印 tid/pid 和名称:
#define for_each_process(p) \
for (p = &init_task ; (p = next_task(p)) != &init_task ; )
如何区分线程和进程?
所以我会这样打印:
if (p->real_parent->pid == NULL)
printk("PROCESS: name: %s pid: %d \n",p->comm,p->pid);
else
printk("THREAD: name: %s tid: %d \n",p->comm,p->pid);