CPU Scheduling Algorithms in Operating SystemsIn this tutorial, we will be learning about the CPU Scheduling Algorithms in Operating Systems. These are algorithms are very important topic in Operating Systems. This is because this CPU Scheduling Algorithms forms a base and foundation for the Operating Systems subject. There are many processes which are going on in the Operating System. A task is a group of processes. Every task is executed by the Operating System. The Operating System divides the task into many processes. The final goal of the Operating System is completion of the task. But there are some certain conditions which must be followed by the task. The conditions are that the Task must be finished in the quickest possible time with the limited resources which the Operating System have. This is the main motive of CPU Scheduling Algorithms. CPU SchedulingThe CPU Scheduling is the process by which a process is executed by the using the resources of the CPU. The process also can wait due to the absence or unavailability of the resources. These processes make the complete use of Central Processing Unit. The operating system must choose one of the processes in the list of ready-to-launch processes whenever the CPU gets idle. A temporary (CPU) scheduler does the selection. The Scheduler choose one of the ready-to-start memory processes to get the CPU. Before, going to the Types of CPU Scheduling Algorithms, we are going to learn about the Basic Terminologies which are to be followed and used in the CPU Scheduling Algorithms by us. 1. Process IDThe Process ID is the first Thing is to be written while solving the problem. The Process ID acts like the name of the process. It is usually represented with numbers or P letter with numbers Example: Usually, we start the naming of the process from zero. We can also start the numbering from number 1 also. It is our interest 1. Arrival Time The time which is required for the Process to enter the ready queue or the time when the Process is ready to be executed by the CPU. This Arrival Time can be represented as AT in short form. The Arrival Times is always positive or also zero. 2. Burst Time The Time Slot which the Process requires to complete the Process is known as the Burst Time. The Burst Time can be represented as BT in short form. The Burst Times of a process is always greater than zero. 3. Completion Time The Total Time required by the CPU to complete the process is known as Completion Time. The Completion Time can be represented as CT in short form. The Completion will always be greater than zero. 4. Turn Around Time The time taken by the CPU since the Process has been ready to execute or since the process is in Ready Queue is known as Turn Around Time. The Turn Around Time can be calculated with the help of Completion Time and Arrival Time. The Turn Around Time can be represented as TAT in short form. The Turn Around Time is the difference of Completion Time and Arrival Time. Formula Here, CT is Completion Time and AT is Arrival Time. 5. Waiting Time The time the Process has been waiting to complete its process since the assignment of process for completion is known as Waiting Time. The Waiting Time can be represented as WT in short form. The Waiting Time can be calculated with the help of Turn Around Time and Burst Time. The Waiting Time is the difference between Turn Around Time and Burst Time Formula 6. Ready Queue The Queue where all the processes are stored until the execution of the previous process. This ready queue is very important because there would be confusion in CPU when two same kinds of processes are being executed at the same time. Then, in these kinds of conditions the ready queue comes into place and then, the its duty is fulfilled. 7. Gantt Chart It is the place where all the already executed processes are stored. This is very useful for calculating Waiting Time, Completion Time, Turn Around Time. Modes in CPU Scheduling AlgorithmsThere are two modes in CPU Scheduling Algorithms. They are:
In Pre Emptive-Approach the process once starts its execution then the CPU is allotted to the same process until the completion of process. There would be no shift of Processes by the Central Processing Unit. The complete CPU is allocated to the Process and there would be no change of CPU allocation until the process is complete. In Non-Pre Emptive-Approach the process once stars its execution, then the CPU is not allotted to the same process until the completion of process. There is a shift of Processes by the Central Processing Unit. The complete CPU is allocated to the Process when only certain required conditions are achieved and there will be change of CPU allocation if there is break or False occurrence in the required conditions. Types of CPU Scheduling Algorithms
First Come First Serve Scheduling AlgorithmThis is the first type of CPU Scheduling Algorithms. Here, in this CPU Scheduling Algorithm we are going to learn how CPU is going to allot resources to the certain process. Here, in the First Come First Serve CPU Scheduling Algorithm, the CPU allots the resources to the process in a certain order. The order is serial way. The CPU is allotted to the process in which it has occurred. We can also say that First Come First Serve CPU Scheduling Algorithm follows First In First Out in Ready Queue. First Come First Serve can be called as FCFS in short form. Characteristics of FCFS (First Come First Serve):
Advantages
Disadvantages
Examples Now, we are going to apply FCFS (First Come First Serve) CPU Scheduling Algorithm for the above problem. In FCFS, there is an exception that Arrival Times are not removed from the Completion Time. Here, in First Come First Serve the basic formulas do not work. Only the basic formulas work.
Gantt ChartAverage Completion Time = The Total Sum of Completion Times which is divided by the total number of processes is known as Average Completion Time. Average Completion Time =( CT1 + CT2 + CT3 + . . . . . . . . . . . + CTn ) / n Average Completion Time Average Turn Around Time = The Total Sum of Turn Around Times which is divided by the total number of processes is known as Average Turn Around Time. Average Turn Around Time = (TAT1 + TAT2 + TAT3 + . . . . . . . . . . . + TATn ) / n Average Turn Around Time Average Waiting Time = The Total Sum of Waiting Times which is divided by the total number of processes is known as Average Waiting Time. Average Waiting Time = (WT1 + WT2 + WT3 + . . . . . . . . . . . + WTn ) / n Average Waiting Time Convoy effectExamples:
The Average Completion Time is: Average CT = ( 79 + 81 + 84 + 85 + 110 + 113 ) / 6 Average CT = 92 The Average Waiting Time is: Average WT = ( 0 + 79 + 81 + 84 + 85 + 110 ) /6 Average WT = 73.1666667 The Average Turn Around Time is: Average TAT = ( 78 + 81 + 83 + 85 + 108 +110 ) / 6 Average TAT = 90.833334 The biggest problem in this is higher Completion Time, higher Waiting Time, higher Turn Around Time, lower efficiency. The problem which we found in the above solution can be resolved by using a new CPU Scheduling Techniques named Shortest Job First (SJF). Shortest Job First CPU Scheduling AlgorithmThis is another type of CPU Scheduling Algorithms. Here, in this CPU Scheduling Algorithm we are going to learn how CPU is going to allot resources to the certain process. The Shortest Job is heavily dependent on the Burst Times. Every CPU Scheduling Algorithm is basically dependent on the Arrival Times. Here, in this Shortest Job First CPU Scheduling Algorithm, the CPU allots its resources to the process which is in ready queue and the process which has least Burst Time. If we face a condition where two processes are present in the Ready Queue and their Burst Times are same, we can choose any process for execution. In actual Operating Systems, if we face the same problem then sequential allocation of resources takes place. Shortest Job First can be called as SJF in short form. Characteristics:
Advantages
Disadvantages
Examples for Shortest Job First Now, we are going to solve this problem in both pre emptive and non pre emptive way We will first solve the problem in non pre emptive way. In Non pre emptive way, the process is executed until it is completed. Non Pre Emptive Shortest Job First CPU Scheduling
Gantt Chart: Now let us find out Average Completion Time, Average Turn Around Time, Average Waiting Time. Average Completion Time: Average Waiting Time: Average Turn Around Time: Pre Emptive ApproachIn Pre emptive way, the process is executed when the best possible solution is found.
Gantt chart: After P4 P5 is executed just because of the Pre Emptive Condition. Now let us find out Average Completion Time, Average Turn Around Time, Average Waiting Time. Average Completion Time Average Turn Around Time Average Waiting Time Priority CPU SchedulingThis is another type of CPU Scheduling Algorithms. Here, in this CPU Scheduling Algorithm we are going to learn how CPU is going to allot resources to the certain process. The Priority CPU Scheduling is different from the remaining CPU Scheduling Algorithms. Here, each and every process has a certain Priority number. There are two types of Priority Values.
Priority for Prevention The priority of a process determines how the CPU Scheduling Algorithm operates, which is a preemptive strategy. Since the editor has assigned equal importance to each function in this method, the most crucial steps must come first. The most significant CPU planning algorithm relies on the FCFS (First Come First Serve) approach when there is a conflict, that is, when there are many processors with equal value. Characteristics
Advantages
Disadvantages
Examples: Now, let us explain this problem with the help of an example of Priority Scheduling Here, in this problem the priority number with highest number is least prioritized. This means 5 has the least priority and 0 has the highest priority. Solution:
Gantt Chart: Average Completion Time Average Waiting Time Average Turn Around Time Round Robin CPU SchedulingRound Robin is a CPU scheduling mechanism those cycles around assigning each task a specific time slot. It is the First come, First served CPU Scheduling technique with preemptive mode. The Round Robin CPU algorithm frequently emphasizes the Time-Sharing method. Round Robin CPU Scheduling Algorithm characteristics include:
The benefits of round robin CPU Scheduling:
Examples: Problem
Solution:
Gantt Chart: Average Completion Time = 7.8 Average Turn Around Time = 4.8 Average Waiting Time = 3 This is all about the CPU Scheduling Algorithms in Operating System. |