Types of CPU Scheduling Algorithms
First-Come, First-Served (FCFS): It is one of the simplest CPU scheduling algorithms. It schedules processes in the order they arrive in the Ready queue. The key principle is that the first process to arrive gets executed first, and the CPU will not switch to another process until the current process finishes its execution. It is non-preemptive scheduling. FCFS Scheduling is simple and easy to implement but can lead to issues like the "convoy effect."
The convoy effect describes the phenomenon where a long process (or a process with a heavy burst time) causes a delay for shorter processes that arrive afterward, resulting in increased average waiting time for those shorter processes.
First Image (Long Process First): If a process with a heavy burst time is placed first, it will occupy the CPU for a long period. Shorter processes that arrive afterward will have to wait until the long process is completed, leading to a high average waiting time for the shorter processes.
If the process with the heavy burst time is placed at the end of the queue, shorter processes will be executed first. This reduces their waiting time since they get the CPU sooner. As a result, the average waiting time for all processes is reduced.
Convoy Effect: Long Process First: Causes the shorter processes to wait longer, increasing their average waiting time. Short Process First: Minimizes waiting time for shorter processes and reduces the average waiting time overall.
Shortest Job First algorithm: In this scheduling approach, the job with the smallest burst time is executed first. However, a question arises: how can we determine which job has the shortest burst time before execution, since it’s not practically possible to know this in advance? The operating system tackles this by making an informed guess, using factors like code size, historical data, or other logical indicators to estimate the burst time. These estimates are not always precise, but they provide a rough idea that helps the OS prioritize processes accordingly.
Non-preemptive Shortest Job First (SJF) can fall victim to the convoy effect. For instance, in the above example, (Non-preemptive Shortest Job First algorithm) if the first process in the queue has a burst time of 80 seconds, it would continue executing, preventing other processes from running and causing them to experience significant delays or starvation.
Preemptive SJF avoids the convoy effect because processes with lower burst times are given higher priority. The convoy effect occurs when a long-running job monopolizes the CPU, leading to the starvation of shorter processes (as shown in the above image). The biggest challenge with the Shortest Job First (SJF) algorithm is that it's practically impossible to implement perfectly, as we can't know the exact burst time of a process before execution.
Priority scheduling: In priority scheduling, the job with the highest priority is executed first, followed by the next highest, and so on. Given below is an example of a non-preemptive version.
From the above image (preemptive version), we can see that the average wait time for the processes is 11.4 units, which is quite high. In fact, its average wait time is greater than that of the non-preemptive version. Additionally, it is susceptible to the convoy effect, as it prioritizes high-priority processes first. If these high-priority processes have long burst times, it can lead to the starvation of lower-priority jobs. Hence the biggest drawback including both preemptive and non-preemptive scheduling is that it causes extreme starvation of low-priority processes. The solution to the starvation problem is aging. Aging involves gradually increasing the priority of lower-priority jobs over time. For example, every 15 seconds, the priority of the lowest-priority job can be increased by +1. This way, the priority of these jobs will slowly rise, ensuring that they eventually get a chance to execute.
Round-Robin Scheduling algorithm: It is a CPU scheduling algorithm that is designed to manage processes in a fair and time-efficient manner. In this algorithm, each process is assigned a fixed time slot called a time quantum (e.g., 10 milliseconds). The CPU executes each process in the order they arrive, giving each process an equal share of CPU time. If a process doesn't finish its execution within its time quantum, it is moved to the back of the queue to wait for its next turn. Selecting an appropriate time quantum is crucial; if it's too short, there will be too many context switches; if it's too long, the system behaves like First-Come, First-Served (FCFS).






Great work
ReplyDelete