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. |