xizero00 发表于 2014-05-12 14:43

idle究竟是核心线程还是进程,求指教

我们知道idle是由原始进程转变而来的,但是看了网上的各种解释有点模糊了。我有以下几个疑问。
这个帖子也让我很郁闷啊。http://bbs.chinaunix.net/thread-4131824-1-1.html
大家都说只有核心线程,然后既然是核心线程为什么又有进程id(pid)。

idle有没有用户上下文?

idle的pid=0又作何解释?既然是核心线程为什么会有pid?

idle是如何实现的,在x86上
我找了一下调用路径是这样的Linux当中是i386_start_kernel(head32.c文件) –>start_kernel(main.c文件)-> rest_init(main.c 文件)-> cpu_idle(arch/x86/kernel/process32.c)void cpu_idle(void)
{
        int cpu = smp_processor_id();

        /*
       * If we're the non-boot CPU, nothing set the stack canary up
       * for us.CPU0 already has it initialized but no harm in
       * doing it again.This is a good place for updating it, as
       * we wont ever return from this function (so the invalid
       * canaries already on the stack wont ever trigger).
       */
        boot_init_stack_canary();

        current_thread_info()->status |= TS_POLLING;

        /* endless idle loop with no priority at all */
        while (1) {
                // 停止进程调度计数是啥意思?
                tick_nohz_stop_sched_tick(1);
                while (!need_resched()) {
                        //检查页表cache,x86上没用,该宏没有任何作用,为什么?
                        check_pgt_cache();
                        rmb();
                        // CPU热插拔?
                        if (cpu_is_offline(cpu))
                                play_dead();
                        // 为什么关本地中断?那又在哪里打开本地中断呢
                        local_irq_disable();
                        /* Don't trace irqs off for idle */
                        stop_critical_timings();
                        // 这玩意的实现在哪里?void (*pm_idle)(void);
                        pm_idle();
                        start_critical_timings();
                }
                tick_nohz_restart_sched_tick();
                preempt_enable_no_resched();
                schedule();
                preempt_disable();
        }
}求高人解释一下具体的含义,

humjb_1983 发表于 2014-05-12 18:39

内核线程?为何不能有pid呢?呵呵

xizero00 发表于 2014-05-12 19:23

那是不是所有的内核线程的pid都为0啊?回复 2# humjb_1983


   

humjb_1983 发表于 2014-05-12 19:41

当然不是,Linux中进程和线程基本待遇是相同的,都有自己的pid。

hejianet 发表于 2014-05-13 10:34

你可以看看ps 输出的内容带[]的都是内核线程
页: [1]
查看完整版本: idle究竟是核心线程还是进程,求指教