当操作系统只是进程之一时,抢占式多任务处理如何工作?

编程入门 行业动态 更新时间:2024-10-27 20:32:42
本文介绍了当操作系统只是进程之一时,抢占式多任务处理如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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.

更多推荐

当操作系统只是进程之一时,抢占式多任务处理如何工作?

本文发布于:2023-07-22 10:41:12,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1186779.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:进程   操作系统   工作

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!