操作系统抢占式优先级调度_操作系统中的优先级调度(抢占式)

操作系统抢占式优先级调度

In the priority scheduling, the processes are scheduled on the basis of their priority, and not on the basis of their burst time. If the preemptive mode of this scheduling is being followed, then a process with a higher priority than the currently executing process can replace the executing process. This can be well explained with the help of the following example:

优先级调度中 ,将根据进程的优先级而不是根据突发时间来调度进程。 如果遵循此调度的抢占模式 ,则优先级高于当前正在执行的进程的进程可以替换正在执行的进程。 可以通过以下示例很好地解释这一点:

Suppose, we have four processes: P1, P2, P3 and P4, and they enter the CPU in the following manner:

假设我们有四个进程: P1P2P3P4 ,它们以以下方式进入CPU:

/priority scheduling 2 in OS

As per the preemptive priority scheduling, the processes will be executed as follows:

根据抢先优先级调度 ,这些过程将按以下方式执行:

Gant Chart

甘特图

/priority scheduling 2 in OS

Explanation:

说明:

  • There is only P1 available at time 0, so it will be executed first irrespective of the priority until some other process with a higher priority is encountered by the OS.

    在时间0只有P1可用,因此它将优先于优先级执行,直到OS遇到其他具有更高优先级的进程为止。

  • At the beginning of the 1st-time unit, we have P2 which has a higher priority than P1, so it replaces P1.

    在第1 -时间单元的开始,我们有P2具有比P1更高的优先级,因此它取代P1。

  • At 2nd time unit, we have the process P3, but its priority is less than the executing process P2, so P2 keeps executing without any replacement.

    第二时间单位,我们有进程P3 ,但是它的优先级小于执行进程P2 ,因此P2继续执行而没有任何替换。

  • At 3rd time unit, our P2 has been completed and till now we have processes P1 and P3 left. So, P1 which has a higher priority than P3 is executed.

    第三个时间单元,我们的P2已完成,到现在为止,我们还有流程P1P3 。 因此,执行优先级高于P3的 P1

  • At 4th time unit, we have process P4 which has the highest priority of them all. So, it replaces P1.

    4 时间单位,我们有进程P4 ,它是所有进程中的最高优先级。 因此,它将替换P1

  • Since now we have no more processes left to arrive, the processes will now run according to their priorities and will complete their execution.

    从现在开始,我们不再需要其他任何流程,这些流程将根据其优先级运行并完成其执行。

/priority scheduling 2 in OS
    Total Turn-Around Time = 8 + 2 + 9 + 2
                = 21 milliseconds
    Average Turn-Around Time= Total Turn-Around Time / Total No. of Processes
                = 21 / 4
                = 5.25 milliseconds

    Total Waiting Time = 4 + 0 + 6 + 0
                = 10 milliseconds
    Average Waiting Time = Total Waiting Time / Total No. of Processes
                = 10 / 4
                = 2.5 milliseconds


翻译自: https://www.includehelp.com/operating-systems/priority-scheduling-preemptive.aspx

操作系统抢占式优先级调度

1. 实验目的 调度的实质是操作系统按照某种预定的策略来分配资源。进程调度的目的是分配CPU资源。由于进程调度程序执行的频率很高,因此调度算法的好坏直接影响到操作系统的性能。本实验的目的是编程模拟实现几种常用的进程调度算法,通过对几组进程分别使用不同的调度算法,计算进程的平均周转时间和平均带权周转时间,比较各种算法的性能优劣。 2. 实验原理 [1]. 进程调度算法描述 进程调度算法包括先来先服务调度算法、最短作业时间优先(抢占和非抢占)、最高响应比调度算法4种。(每个人必须做FCFS,然后在后面的三种任选一种,即每个人必须做2种调度算法的模拟。) [2]. 衡量算法性能的参数 计算进程的平均周转时间和平均带权周转时间。 3. 实验内容 (1)编程实现本实验的程序,要求: [1]. 建立进程的进程控制块,进程控制块至少包括: a) 进程名称; b) 进程需要执行时间; c) 进入就绪队列时间; d) 进程执行开始时间 e) 进程执行结束时间 [2]. 编程实现调度算法。 [3]. 进程及相关信息的输入。这些信息可以直接从键盘上输入,也可以从文件读取。 [4]. 时间片与时间流逝的模拟。本实验需要对算法的执行计时,程序应该提供计算时间的方法。一种最简单的方法是使用键盘,比如每敲一次空格代表一个时间片的流逝。另一种方法是使用系统时钟。 [5]. 一组进程序列执行完毕,打印出结果信息。程序需要计算出每个进程的开始执行时间、结束时间、周转时间和带权周转时间,并为整个进程序列计算平均周转时间和平均带权周转时间。程序将计算结果按一定的格显示在计算机屏幕上或输出到文件。打印出进程调度顺序图。 [6]. 实现数据在磁盘文件上的存取功能。 (2)对下列就绪进程序列分别使用上面的几种算法进行调度,计算每种算法下的平均周转时间和平均带权周转时间。 进程号 到达时间 要求执行时间 0 0 1 1 1 35 2 2 10 3 3 5 4 6 9 5 7 21 6 9 35 7 11 23 8 12 42 9 13 1 10 14 7 11 20 5 12 23 3 13 24 22 14 25 31
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值