In: Computer Science
11. Consider three processes P1, P2, and P3, and all them three are ready to run at time = 0. Each process has two CPU bursts. When its first CPU burst is completed, each process requests a blocking I/O operation on a separate I/O device. When a process starts to receive service for I/O, the OS scheduler selects and dispatches another process available at the ready queue. The CPU scheduling policy is preemptive priority-based scheduling, where a process being running can be preempted at the arrival of a higher priority process (think about how a preemptive SJF preempts a job currently being running). A smaller priority value indicates a higher priority. Assume the system has only one CPU core.
Process Priority 1st CPU burst I/O burst 2nd CPU burst
P1 1 5 20 5
P2 2 5 10 10
P3 3 5 4 5
Draw the Gantt chart for the above system (make sure to highlight process preemption and completion); calculate the average turnaround time and average waiting time – show your work.
Preemptive Priority Scheduling:
In this algorithm, a process with highest priority will execute first for some fixed time. It is the pre-emptive algorithm.
The next highest priority process will execute only after completion of the execution of the before process for some fixed time. Let the timestamp is 5.
Here, a smaller priority number means higher execution priority. That is priority number 1 is the higher execution priority.
When its first CPU burst is completed, each process requests a blocking I/O operation on a separate I/O device.
When a process starts to receive service for I/O, the OS scheduler selects and dispatches another process available at the ready queue.
Gantt diagram for Preemptive Priority Scheduling:
Now, calculate the turnaround time to find the waiting time.
Turnaround time = Completion time – Arrival time
Waiting time = Turnaround time - Burst time
Total turnaround time = Sum of turnaround times of all processes
Total turnaround time = 30+35+39= 104
Average turnaround time = Sum of turnaround times of all processes/ number of process
Average turnaround time =104/3=34.67
Total waiting time = Sum of waiting times of all processes
Total waiting time = 20+20+29= 69.
Average waiting time = Sum of waiting times of all processes/ number of process
Average waiting time = 69/ 3 = 23
Therefore, using Preemptive Priority Scheduling, the average turnaround time is 34.67 and the average waiting time is 23.