C
我想迭代内核中的所有任务(线程和进程)并使用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);
以下宏是你需要的:
/*
* Careful: do_each_thread/while_each_thread is a double loop so
* 'break' will not work as expected - use goto instead.
*/
#define do_each_thread(g, t)
for (g = t = &init_task ; (g = t = next_task(g)) != &init_task ; ) do
#define while_each_thread(g, t)
while ((t = next_thread(t)) != g)
像这样使用它们:
rcu_read_lock();
do_each_thread(g, t) {
//...
} while_each_thread(g, t);
rcu_read_unlock();
链接地址: http://www.djcxy.com/p/67753.html
上一篇: c
下一篇: insensitive search