为什么我们在Linux中需要交换任务? [英] Why do we need a swapper task in linux?

查看:58
本文介绍了为什么我们在Linux中需要交换任务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在任务调度时,如果运行队列中没有可运行的任务,则选择运行空闲任务(也称为交换任务).但是,这项特殊任务的用途是什么?另一个问题是为什么我在用户区的"ps aux"输出(PID = 0)中找不到此线程/进程?

The idle task (a.k.a. swapper task) is chosen to run when no more runnable tasks in the run queue at the point of task scheduling. But what is the usage for this so special task? Another question is why i can't find this thread/process in the "ps aux" output (PID=0) from the userland?

推荐答案

原因是历史性和程序性的.空闲任务是正在运行的任务,如果没有其他任务是可运行的(如您所说).它具有最低的优先级,因此这就是为什么它没有其他可运行任务的原因.

The reason is historical and programatic. The idle task is the task running, if no other task is runnable, like you said it. It has the lowest possible priority, so that's why it's running of no other task is runnable.

程序上的原因:这大大简化了流程调度,因为您不必在意以下特殊情况:如果没有可运行的任务会发生什么?",因为始终至少有一个可运行的任务,即闲置任务.您还可以计算每个任务使用的cpu时间.如果没有空闲任务,哪个任务不需要占用任何人的CPU时间?

Programatic reason: This simplifies process scheduling a lot, because you don't have to care about the special case: "What happens if no task is runnable?", because there always is at least one task runnable, the idle task. Also you can count the amount of cpu time used per task. Without the idle task, which task gets the cpu-time accounted no one needs?

历史原因:在拥有能够降级或进入省电模式的cpus之前,它必须随时全速运行.如果没有可运行的任务,它将运行一系列NOP指令.今天,空闲任务的调度通常通过使用HLT指令(暂停)来降低CPU的功耗,从而节省了功率.因此,当今的空闲任务中有某种功能.

Historical reason: Before we had cpus which are able to step-down or go into power saving modes, it HAD to run on full speed at any time. It ran a series of NOP-instructions, if no tasks were runnable. Today the scheduling of the idle task usually steps down the cpu by using HLT-instructions (halt), so power is saved. So there is a functionality somehow in the idle task in our days.

在Windows中,您可以在进程列表中看到空闲任务,它是空闲进程.

In Windows you can see the idle task in the process list, it's the idle process.

这篇关于为什么我们在Linux中需要交换任务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆