免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 8291 | 回复: 2
打印 上一主题 下一主题

linux的idle线程有什么作用? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-01-21 16:11 |只看该作者 |倒序浏览
在run queue的结构中:

  1. sched.c:
  2. struct rq {
  3. struct task_struct *curr, *idle;
  4.    ....
  5. }
复制代码

idle是内核的idle线程。这个idle线程到底有什么用处?另外在ps aux命令输出中怎么找不到它(PID=0?)?

论坛徽章:
0
2 [报告]
发表于 2009-01-21 19:51 |只看该作者
idle线程的用处在ULK3上面第3章有讲解。
After having created the init process, process 0 executes the cpu_idle( ) function, which essentially consists of repeatedly executing the hlt assembly language instruction with the interrupts enabled (see Chapter 4). Process 0 is selected by the scheduler only when there are no other processes in the TASK_RUNNING state.


至于ps中没有显示这个进程,这就要看ps的实现的。在/proc目录下面没有进程0的目录项。另外,在内核中提供了for_each_process宏来遍历所有的进程,但是这个宏却不会对init_task进程,即0号进程进行一些操作。你可以查看一下这个宏。

另外,我想你也可以看看下面这个贴子:
http://linux.chinaunix.net/bbs/viewthread.php?tid=653764###

论坛徽章:
0
3 [报告]
发表于 2009-01-21 22:39 |只看该作者
要想一个操作系统不干活的时候在那里转,有活的时候就干。

逻辑上也需要个循环在那里转。

这个大循环就是idle
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP