抢占式与非抢占式调度

When the CPU is in the idle state, the CPU scheduler chooses a process from the ready queue and allocates the process to CPU. There are two types of scheduling,

当CPU处于空闲状态时,CPU调度程序从就绪队列中选择一个进程,并将该进程分配给CPU。 调度有两种类型,

  1. Preemptive Scheduling 抢占式调度
  2. Non-Preemptive Scheduling 非抢占式调度

(1) Preemptive Scheduling)

Once a process started its execution, scheduling occurs at the time of a process switches from running state to ready state and from waiting state to ready state is called Preemptive Scheduling.

一旦进程开始执行,调度就在进程从运行状态切换到就绪状态以及从等待状态切换到就绪状态时发生,称为抢先调度。

In this scheduling resources (CPU cycles) are allocated to the process for a short period of time and if some process of higher priority is encountered then the current process can be paused to handle that process.

在这种调度中,资源(CPU周期)会在短时间内分配给该进程,如果遇到某些优先级更高的进程,则可以暂停当前进程以处理该进程。

  • Then resources from the currently running process taken away, and the currently running process is placed back in the ready queue again if it still has remaining CPU burst time. That is we can preempt the control of CPU from one process to another if required. The process remains in a ready queue till it gets the next time slot to get executed. 然后,如果仍然有剩余的CPU突发时间,则会从当前正在运行的进程中删除资源,并将当前正在运行的进程再次放回到就绪队列中。 也就是说,如果需要,我们可以抢先将CPU的控制从一个进程转移到另一个进程。 该过程将一直处于就绪队列中,直到获得下一个要执行的时隙为止。
  • By implementing this type of scheduling user can work on multiple processes that are it supports multitasking. 通过实现这种类型的调度,用户可以在支持多任务的多个进程上工作。
  • Examples of Preemptive Scheduling are Round Robin (RR), Shortest Remaining Time First (SRTF), Priority (preemptive version), etc. 抢占式调度的示例包括循环调度(RR),最短剩余时间优先(SRTF),优先级(抢占版本)等。

(2) Non-Preemptive Scheduling)

Once a process started its execution, scheduling occurs when a process terminates, or a process switches from running to waiting state.

一旦进程开始执行,调度将在进程终止或进程从运行状态切换到等待状态时进行。

  • When the resources (CPU) are allocated to a process, the process holds the CPU till it gets terminated or it reaches a waiting state. 当将资源(CPU)分配给进程时,该进程将保持CPU直到其终止或达到等待状态。
  • In non-preemptive scheduling, the scheduler does not interrupt a currently running process in the middle of the execution. But it waits for the process to complete its execution with the CPU, after that it can allocate the CPU to another process. 在非抢占式调度中,调度程序在执行过程中不会中断当前正在运行的进程。 但是它等待进程完成其与CPU的执行,然后可以将CPU分配给另一个进程。
  • FCFS scheduling is an example of non-preemptive scheduling. FCFS调度是非抢占式调度的一个示例。

(Differences between Preemptive and Non-Preemptive Scheduling in OS)

  • In the middle of the execution of a process the execution is interrupted whereas; in non-preemptive scheduling, execution is not interrupted in the middle of execution. 在执行过程的中间,执行被中断,而; 在非抢占式调度中,在执行过程中不会中断执行。
  • Preemptive Scheduling suffers from the overhead of switching between processes from the ready state to running state, vice-verse, and maintaining the ready queue. On the other hand, non-preemptive scheduling does not suffer from the overhead of switching the process from running state to ready state. 抢先式调度会遭受从就绪状态到运行状态(反之亦然)之间进行切换以及维护就绪队列的开销。 另一方面,非抢占式调度不会遭受将进程从运行状态切换到就绪状态的开销。
  • When a high priority process arrives frequently in the ready queue then the process with low priority has to wait for a long time, and it may have to starve, in preemptive scheduling. Whereas in the non-preemptive scheduling, if CPU is allocated to the process with larger burst time then the processes with smallest burst time may have to starve. 当高优先级的进程频繁到达就绪队列时,低优先级的进程必须等待很长时间,并且可能会在抢占式调度中饿死。 而在非抢占式调度中,如果将CPU分配给具有较大突发时间的进程,则突发时间最小的进程可能不得不挨饿。
  • The critical processes are allowed to access CPU whenever they arrive into the read queue. In this way preemptive scheduling is flexible. While non-preemptive scheduling is rigid because if a critical process enters the ready queue the process running CPU not disturbed. 只要关键进程进入读取队列,就可以访问它们。 这样,抢占式调度是灵活的。 非抢占式调度很严格,因为如果关键进程进入就绪队列,则运行CPU的进程不会受到干扰。
  • The Preemptive Scheduling has to maintain the integrity of shared data so it is cost associative but it is not the case with non-preemptive Scheduling. 抢先式调度必须维护共享数据的完整性,因此这与成本相关,但非抢先式调度则不是这种情况。
  • The main difference between these two schedules is that in non-preemptive scheduling, the CPU is allocated to the process till it completes its execution or switches from running state to waiting state. Whereas in preemptive scheduling the CPU is allocated to a process for a limited amount of time. 这两个调度之间的主要区别在于,在非抢占式调度中,CPU被分配给进程,直到它完成执行或从运行状态切换到等待状态。 而在抢占式调度中,CPU将在有限的时间内分配给某个进程。

References:

参考文献:

  • Difference Between Preemptive and Non-Preemptive Scheduling in OS 抢占式和非抢占式调度之间的区别
  • Difference between preemptive and non-preemptive scheduling in Operating systems 操作系统中的抢占式和非抢占式调度之间的区别

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

抢占式与非抢占式调度