- 论坛徽章:
- 0
|
有一个办法可以把所有任务全部打印出来,就是自己写一个内核模块,然后在用户态通过某种方式(可以通过写虚拟设备等),执行内核模块的一个函数 ,这个函数就是调用 show_state,魔术键的sysrq.c就是调用这个函数打印所有任务的调用栈的,由于当前任务是自己的测试任务,因此其他任务可以全部打印(不过SMP的情况,其他CPU的正在执行的还是搞不定)。
当然自己也可以在内核模块内重新写这个函数,把最后的一个判断去掉。不过不清楚内核为什么要加这个判断,可能是怕调用栈不准确
static void show_task(task_t * p)
{
task_t *relative;
unsigned state;
unsigned long free = 0;
static const char *stat_nam[] = { "R", "S", "D", "T", "t", "Z", "X" };
printk("%-13.13s ", p->comm);
state = p->state ? __ffs(p->state) + 1 : 0;
if (state < ARRAY_SIZE(stat_nam))
printk(stat_nam[state]);
else
printk("?");
#if (BITS_PER_LONG == 32)
if (state == TASK_RUNNING)
printk(" running ");
else
printk(" %08lX ", thread_saved_pc(p));
#else
if (state == TASK_RUNNING)
printk(" running task ");
else
printk(" %016lx ", thread_saved_pc(p));
#endif
#ifdef CONFIG_DEBUG_STACK_USAGE
{
unsigned long * n = (unsigned long *) (p->thread_info+1);
while (!*n)
n++;
free = (unsigned long) n - (unsigned long)(p->thread_info+1);
}
#endif
printk("%5lu %5d %6d ", free, p->pid, p->parent->pid);
if ((relative = eldest_child(p)))
printk("%5d ", relative->pid);
else
printk(" ");
if ((relative = younger_sibling(p)))
printk("%7d", relative->pid);
else
printk(" ");
if ((relative = older_sibling(p)))
printk(" %5d", relative->pid);
else
printk(" ");
if (!p->mm)
printk(" (L-TLB)\n");
else
printk(" (NOTLB)\n");
if (state != TASK_RUNNING) // 这里判断了,原来只要是就绪态的都不打印,还是比较恶心的。我前面的描述有误
show_stack(p, NULL);
} |
|