📌  相关文章
📜  抢占式和非抢占式 CPU 调度算法的区别

📅  最后修改于: 2021-09-11 04:06:10             🧑  作者: Mango

在CPU调度中,我们有两种调度方式,让我们来看看它们:

抢占式调度:
在这种情况下,当高优先级进程进入就绪状态时,调度器可以随时抢占低优先级正在运行的进程。当调度来自以下任一情况时,它是抢占式调度——

  • 当进程从运行状态切换到就绪状态时(例如,发生中断时)。
  • 当进程从等待状态切换到就绪状态时(例如,在完成 I/)时)。

非抢占式调度:
在这种情况下,一旦一个进程进入运行状态,它就不能被抢占,直到它完成它的分配时间。当调度仅在以下情况下发生时,我们说调度方案是非抢占式合作式的。 ——

  • 当进程从运行状态切换到等待状态时(例如,作为 I/O 请求或调用 wait() 以终止子进程的结果)。
  • 当一个进程终止时。

让我们看看抢占式调度和非抢占式调度之间的区别:

S.No. Preemptive Scheduling Non-Preemptive Scheduling
1. The CPU is allocated to the processes for a certain amount of time. The CPU is allocated to the process till it ends it’s execution or switches to waiting state.
2. The executing process here is interrupted in the middle of execution. The executing process here is not interrupted in the middle of execution.
3. It usually switches the process from ready state to running state, vise-versa, and maintains the ready queue. It does not switch the process from running state to ready state.
4. Here, if a process with high priority frequently arrives in the ready queue then the process with low priority has to wait for long, and it may have to starve. Here, if CPU is allocated to the process with larger burst time then the processes with small burst time may have to starve. 5. It is quite flexible because the critical processes are allowed to access CPU as they arrive into the ready queue, no matter what process is executing currently. It is rigid as even if a critical process enters the ready queue the process running CPU is not disturbed. 6. This is cost associative as it has to maintain the integrity of shared data. This is not cost associative.


抢占式调度优于非抢占式调度,反之亦然不能肯定。这取决于调度如何最小化进程的平均等待时间并最大化 CPU 利用率。