1.先到先得(FCFS):
先来先服务(FCFS)是最简单的算法类型。这是一种非抢占式算法,即该流程一旦开始执行就无法中断。 FCFS是通过FIFO队列实现的。流程按到达时间的顺序放入就绪队列。首先到达的进程将成为队列的头,而其他随后到达的进程将被添加到队列的尾部。在先来先服务(FCFS)算法中,当CPU空闲时,首先到达的进程将首先发送给CPU执行。
该算法的主要缺点是平均等待时间通常很长。这也会导致车队效应。这导致较低的设备或CPU利用率以及较低的效率。
2.优先级调度算法:
优先级调度算法根据进程的优先级执行进程。为每个进程分配一个优先级,并首先执行具有最高优先级的进程。可以在内部和外部定义优先级。内部优先级是由系统根据所需的资源数量,所需的时间等决定的,而外部优先级则取决于需要工作的时间或为完成的工作支付的金额或过程的重要性。优先级调度可以是抢占式的也可以是非抢占式的。
笔记-
- 如果两个进程具有相同的优先级,则使用FCFS断开连接。
- 在抢占模式下,最高优先级进程的等待时间始终为零,而在非抢占模式下的等待时间可能不为零。
缺点:
主要问题是饥饿或无限期封锁。可能会发生这样的情况,即在进程流中,系统会继续执行高优先级进程,而永远不会执行低优先级进程。
解决方案:
解决该问题的方法是老化。老化是指在固定间隔后(例如,每10分钟增加1个),以固定数量逐渐增加系统中等待进程的优先级。这将确保通过随着时间的推移缓慢增加其优先级来执行低优先级的进程。
FCFS和优先级调度算法之间的区别:
First Come First Served (FCFS) | Priority scheduling |
---|---|
It executes the processes in the order in which they arrive i.e., the process that arrives first is executed first. | It executes the processes based upon their prioritied i.e., in descending order of their priorities. A process with higher priority is executed first. |
It is non preemptive in nature. | It is both non-preemptive and preemptive in nature. |
It results in quite long waiting time for the processes and thus increases average waiting time. | There is no idea of response time and waiting time. |
It leads to the convoy effect. | It may happen that a low priority process keeps waiting for an indefinite time and never gets executed. |
It is the easiest to implement in any system. | It is best suited for real time operating systems. |