📌  相关文章
📜  优先级调度和最短作业优先(SJF)CPU调度之间的区别

📅  最后修改于: 2021-08-24 05:05:49             🧑  作者: Mango

1.优先级调度算法:
优先级调度算法根据进程的优先级执行进程。为每个进程分配一个优先级,并首先执行具有最高优先级的进程。可以在内部和外部定义优先级。内部优先级是由系统根据所需的资源数量,所需的时间等决定的,而外部优先级则取决于需要工作的时间或为完成的工作支付的金额或过程的重要性。优先级调度可以是抢占式的也可以是非抢占式的。

笔记 –

  • 如果两个进程具有相同的优先级,则使用FCFS断开连接。
  • 在抢占模式下,最高优先级进程的等待时间始终为零,而在非抢占模式下的等待时间可能不为零。

缺点:
主要问题是饥饿或无限期封锁。可能会发生这样的情况,即在进程流中,系统会继续执行高优先级进程,而永远不会执行低优先级进程。

2.最短工作优先(SJF):
最短作业优先(SJF)调度算法基于进程的突发时间。根据进程的突发时间将其放入就绪队列。在该算法中,首先处理突发时间最少的过程。仅比较那些在该时间之前存在或已经到达的进程的突发时间。它在本质上也是非抢先的。它的抢占版本称为最短剩余时间优先(SRTF)算法。

该算法的主要优点在于,它为给定的一组处理提供了最小的等待时间,从而减少了平均等待时间。该算法的缺点是长进程可能永远不会被系统处理,并且可能会在队列中保留很长时间,从而导致进程匮乏。

笔记 –
如果两个进程的突发时间相同,则使用FCFS断开连接,即首先处理最先到达的进程。最短作业优先(SJF)与优先级调度算法之间的区别如下:

Shortest job first (SJF) Priority scheduling
Shortest Job First (SJF) executes the processes based upon their burst time i.e. in ascending order of their burst times. Priority scheduling executes the processes based upon their priorities i.e. in descending order of their priorities. A process with higher priority is executed first.
SJF is also non-preemptive but its preemptive version is also there called Shortest Remaining Time First (SRTF) algorithm. Priority scheduling is both preemptive and non preemptive in nature.
The average waiting time for given set of processes is minimum. There is no idea of average waiting time and response time.
The real difficulty with SJF is knowing the length of the next CPU request or burst. It is quite easy to implement and best for real time operating systems.
A long process may never get executed and the system may keep executing the short processes. The problem of blocking of a process can be solved through aging which means to gradually increase the priority of a process after a fixed interval of time by a fixed number.