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