抢占式多任务处理如何工作

抢占式多任务处理如何工作

本文介绍了当操作系统只是进程之一时,抢占式多任务处理如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在正在阅读有关抢占式多任务处理的材料 - 有一件事让我无法理解.

I am now reading materials about preemptive multitasking - and one thing escapes me.

所有材料都暗示,操作系统以某种方式从外部"中断了 CPU 上正在运行的进程,从而导致上下文切换等.

All of the materials imply, that operating system somehow interrupts the running processes on the CPU from the "outside", therefore causing context switching and the like.

但是,当操作系统的内核只是 CPU 上的另一个进程时,我无法想象这将如何工作.当另一个进程已经在占用CPU时,OS怎么会导致从外部"切换?

However, I can't imagine how would that work, when operating system's kernel is just another process on the CPU. When another process is already occuping the CPU, how can the OS cause the switch from the "outside"?

推荐答案

操作系统不仅仅是另一个进程.当中断发生时,操作系统控制系统的行为.

The OS is not just another process. The OS controls the behavior of the system when an interrupt occurs.

在调度器启动进程之前,它会安排在时间片结束时发送一个定时器中断.假设在此之前没有其他事情发生,定时器将触发,内核将接管控制.如果它选择调度一个不同的进程,它会切换出去以允许另一个进程运行,然后从中断中返回.

Before the scheduler starts a process, it arranges for a timer interrupt to be sent when the timeslice ends. Assuming nothing else happens before then, the timer will fire, and the kernel will take over control. If it elects to schedule a different process, it will switch things out to allow the other process to run and then return from the interrupt.

这篇关于当操作系统只是进程之一时,抢占式多任务处理如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 05:33