操作系统原理,交互式系统常见的调度算法,时间片轮转RR,虚拟轮转VRR,最高优先级调度,优先级反转问题与应对

操作系统原理,交互式系统常见的调度算法,时间片轮转RR,虚拟轮转VRR,最高优先级调度,优先级反转问题与应对

一、交互式系统中采用的调度算法:
1、时间片轮转调度RR,round robin
2、最高优先级调度HPF,hignest priority first
3、多级反馈队列multiple feedback queue
4、最短进程优先shortest process next
5、指标:响应时间,公平平衡

二、时间片轮转调度算法RR,round Robin
1、将CPU时间划分为时间片,挨个切换进程,用完了自己的时间片的进程排到末尾等待

在这里插入图片描述

2、目标:为短任务改善平均响应时间
3、思路:周期性切换,每个进程分配一个时间片,始终中断引发轮换
4、时间片的选择,不能能过长或过短,按照经验选择在10ms-100ms之间
5、优点:公平,有利于交互式计算,响应快,在进程交互时间不同时有利
6、缺点:进程切换较多,开销较大,通常以切换开销约占时间片的1%较为合适;同时平均周转时间会长一些

三、虚拟轮转法virtual RR
1、在时间片轮转算法的基础上,对IO密集型进程多一点思考
2、IO密集型进程对CPU 的使用较少&

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
RR时间片轮转算法的实现: ```python class Process: def __init__(self, pid, burst_time): self.pid = pid self.burst_time = burst_time self.remaining_time = burst_time def execute(self, time_quantum): if self.remaining_time <= time_quantum: executed_time = self.remaining_time self.remaining_time = 0 else: executed_time = time_quantum self.remaining_time -= time_quantum return executed_time def is_completed(self): return self.remaining_time == 0 class RoundRobinScheduler: def __init__(self, processes, time_quantum): self.processes = processes self.time_quantum = time_quantum self.queue = [] def execute(self): current_time = 0 while True: # Add arriving processes to the queue for process in self.processes: if process.burst_time > 0 and process not in self.queue: self.queue.append(process) # If all processes have completed, exit the loop if len(self.queue) == 0: break # Get the first process in the queue process = self.queue.pop(0) # Execute the process for the time quantum executed_time = process.execute(self.time_quantum) current_time += executed_time # If the process is not completed, add it back to the queue if not process.is_completed(): self.queue.append(process) return current_time ``` HPF优先级调度算法的实现: ```python class PriorityScheduler: def __init__(self, processes): self.processes = processes self.queue = [] def execute(self): current_time = 0 while True: # Add arriving processes to the queue for process in self.processes: if process.burst_time > 0 and process not in self.queue: self.queue.append(process) # If all processes have completed, exit the loop if len(self.queue) == 0: break # Sort the queue by priority self.queue.sort(key=lambda x: x.priority, reverse=True) # Get the highest-priority process in the queue process = self.queue.pop(0) # Execute the process executed_time = process.execute(process.burst_time) current_time += executed_time return current_time ``` 注意:需要在 `Process` 类中添加一个 `priority` 属性来表示进程的优先级

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值