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

查看:26
本文介绍了为什么我们需要在 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​​-time?

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?

历史原因:在我们拥有能够降压或进入省电模式的CPU之前,它必须随时全速运行.如果没有可运行的任务,它会运行一系列 NOP 指令.今天空闲任务的调度通常通过使用 HLT 指令 (halt) 来降低 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天全站免登陆