Princess Noura bint Abdulrahman University Faculty of Computer
Princess Noura bint Abdulrahman University Faculty of Computer and Information Sciences Computer science Dept. CS 340 d: Operating Systems CPU scheduling Exercises L. Maram Al. Shablan
2 CPU Scheduling Exercises from textbook
3 From Textbook 6. 3 Suppose that the following processes arrive for execution at the times indicated. Each process will run for the amount of time listed. In answering the questions, use nonpreemptive scheduling, and base all decisions on the information you have at the time the decision must be made. L. Maram Al. Shablan
From Textbook 4 6. 3 (a) What is the average turnaround time for these processes with the FCFS scheduling algorithm? P 1 0 P 3 P 2 8 Waiting time for P 1 = 0 Waiting time for P 2 = 8 - 0. 4 =7. 6 Waiting time for P 3 = 12 -1=11 Average turnaround time= (8+4+1+7. 6+11)/3 = 10. 53 ms 12 13 L. Maram Al. Shablan
From Textbook 5 6. 3 (b) What is the average turnaround time for these processes with the SJF scheduling algorithm? P 1 0 P 2 P 3 8 9 Waiting time for P 1 = 0 Waiting time for P 2 = 9 - 0. 4 =8. 6 Waiting time for P 3 = 8 - 1 =9 Average turnaround time= (8+4+1+8. 6+9)/3 = 9. 53 ms 13 L. Maram Al. Shablan
6 From Textbook The SJF algorithm is supposed to improve performance, but notice that we chose to run process P 1 at time 0 because we did not know that two shorter processes would arrive soon. L. Maram Al. Shablan
7 6. 3 (C) From Textbook What the average turnaround time will be if the CPU is left idle for the first 1 unit and then SJF scheduling is used. Remember that processes P 1 and P 2 are waiting during this idle time, so their waiting time may increase. This algorithm called future-knowledge scheduling. P 2 P 3 1 2 Waiting time for P 1 = 6 Waiting time for P 2 = 1. 6 Waiting time for P 3 = 0 Average turnaround time= 20. 6/3 = 6. 86 ms P 1 6 14 L. Maram Al. Shablan
8 From Textbook 6. 16 Consider the following set of processes, with the length of the CPU burst given in milliseconds: The processes are assumed to have arrived in the order P 1, P 2, P 3, P 4, P 5, all at time 0. L. Maram Al. Shablan
From Textbook 9 6. 16 (a) Draw four Gantt charts that illustrate the execution of these processes using the following scheduling algorithms: FCFS, SJF, nonpreemptive priority (a larger priority number implies a higher priority), and RR (quantum = 2). The Gantt Chart for FCFS: P 1 0 P 2 2 P 4 P 3 3 11 P 5 15 L. Maram Al. Shablan 20
From Textbook 10 6. 16 (a) The Gantt Chart for SJF: P 1 P 2 P 4 1 0 P 3 P 5 3 20 12 7 The Gantt Chart for nonpreemptive priority: P 3 P 5 P 1 P 2 P 4 L. Maram Al. Shablan 0 8 13 15 19 20
From Textbook 11 6. 16 (a) The Gantt Chart for RR (quantum = 2): P 2 P 1 0 2 P 4 P 3 3 5 7 P 4 P 3 P 5 9 11 P 5 13 P 5 P 3 15 17 P 3 18 20 L. Maram Al. Shablan
12 Time Quantum and Context Switch Time in RR scheduling algorithm L. Maram Al. Shablan
13 SJF Scheduling Extra Examples
14 Draw Gantt charts that illustrate the execution of these processes using the following scheduling algorithms: Non-preemptive SJF Preemptive SJF L. Maram Al. Shablan
15 Non-preemptive SJF L. Maram Al. Shablan
16 Preemptive SJF L. Maram Al. Shablan
17 Thank you L. Maram Al. Shablan
- Slides: 17