In: Computer Science
Explain RR scheduling uses preemption and priorities. (b) Does RR scheduling use multiple classes of processes? Why? Explain.
RR scheduling uses preemption and priorities:
In the Pre-emptive category of scheduling algorithms, a process which is allocated to the processor can be stopped and the running state of the corresponding process is changes to waiting state.Suspending the processes that are logically runnable is called Preemptive Scheduling. The resources are allocated to a process for a partial time. Process can be interrupted in between.
The RR algorithm provides equal chance of execution to all the processes in the process set.The RR algorithm does not consider the priorities of the processes which can be considered as the major drawback. RR scheduling uses preemption and priorities overcome this limitation of RR algorithm.
This algorithm categorizes the processes as High priority processes and low priority processes. The proposed scheme reduces the average waiting time of high priority process irrespective of the low priority process. The overall average waiting time will change according to the set of processes considered.
Step 1: Enter process name, priority and burst time.
Step 2: Store the above details in a queue called READYQ
Step 3: Create two separate queues, first HIGHPQ for high priority processes and second LOWPQ for normal priority processes.
Step 4: Do step 5 to step 11 until remaining CPU burst time of processes of both the queues (HIGHPQ and LOWPQ) become zero.
Step 5: Select next process from either HIGHPQ or LOWPQ on alternate basis. First, a process form HIGHPQ must be selected as it should get priority over normal priority processes.
Step 6: If the remaining CPU burst time of selected process is greater than or equal to time quantum then do step 7, otherwise do step 8.
Step 7: Execute that process for duration of time quantum.
Step 8: Execute the selected process until its remaining burst time become zero.
Step 9: Update the remaining CPU burst time of the respective process in respective queue.
Step 10: Store the IN-TIME and OUT-TIME of the process into a table GANTTCHART.
Step 11: If above process has selected from HIGHPQ then swap the next turn to LOWPQ and vice versa.
Example:
Process Name Priority Burst Time
P0 0 5
P1 1 3
P2 1 12
P3 0 9
P4 0 8
HIGHPQ: This queue contains the processes of high priority.
Process Name Priority Burst Time
P1 1 3
P2 1 12
LOWQPQ: This queue contains the processes of low priority.
Process Name Priority Burst Time
P0 0 5
P3 0 9
P4 0 8
A process from high priority queue is selected first then next process is selected from low priority queue
The Gantt chart for the processes with time quantum 4 is
Process In time Out time
P1 0 3
P0 3 7
P2 7 11
P3 11 15
P2 15 19
P4 19 23
P2 23 27
P0 27 28
P3 28 32
P4 32 36
P3 36 37
The waiting time for the processes is
Process PR WT
P0 0 23
P1 1 0
P2 1 15
P3 0 28
P4 0 28
RR scheduling does not use multiple classes of processes because it is a time sharing algorithm .