CSC520 – Chapter 4 Exercise Solutions

download CSC520 – Chapter 4 Exercise Solutions

of 13

Transcript of CSC520 – Chapter 4 Exercise Solutions

  • 8/13/2019 CSC520 Chapter 4 Exercise Solutions

    1/13

  • 8/13/2019 CSC520 Chapter 4 Exercise Solutions

    2/13

    Exercise

    Suppose a system uses priority schedulingwhere a small integer means higher priority

    Create a Gantt chart to illustrate the execution of

    these processes What is the turnaround time for process P2 under

    priority scheduling? What is the average waiting time for the

    processes?

  • 8/13/2019 CSC520 Chapter 4 Exercise Solutions

    3/13

    Turnaround time for P2 160 Waiting time

    P0 70 P1 0 P2 150 P3 160 P4 20

    Average waiting time 400/5 = 80

    P1 P4 P2P0 P30 20 70 150 160 180

  • 8/13/2019 CSC520 Chapter 4 Exercise Solutions

    4/13

  • 8/13/2019 CSC520 Chapter 4 Exercise Solutions

    5/13

  • 8/13/2019 CSC520 Chapter 4 Exercise Solutions

    6/13

    Exercise

    Suppose a system uses SJN scheduling wherea small integer means higher priority

    Create a Gantt chart to illustrate the execution of

    these processes What is the turnaround time for process P3 under

    SJN scheduling? What is the average waiting time for the

    processes?

  • 8/13/2019 CSC520 Chapter 4 Exercise Solutions

    7/13

    P3 Turnaround time 95 55 = 40

    Waiting Time P0 0 P1 150 P2 85 P3 20 P4 65

    Average waiting time 320/5 = 64

    P0 P30 75 95

    P2120

    P1160

    P4205

  • 8/13/2019 CSC520 Chapter 4 Exercise Solutions

    8/13

    Exercise

    Based on the information given below, draw aGantt chart illustrating the execution of eachprocess using the following algorithms

    FCFS SJF Priority Scheduling

    Calculate the waiting time for Process B and Dfor each of the scheduling algorithm

  • 8/13/2019 CSC520 Chapter 4 Exercise Solutions

    9/13

    FCFS/SJF PB 9 FCFS/SJF PD 12

    Priority PB 14 Priority PD 7

    A

    0 10

    B

    12

    C

    15

    D

    20

    A

    0 10

    B

    12

    C

    15

    D

    20

    A

    0 10

    D

    15

    B

    17

    C

    20

  • 8/13/2019 CSC520 Chapter 4 Exercise Solutions

    10/13

    Exercise

    Based on the information given below, draw aGantt chart illustrating the execution of eachprocess using the priority scheduling

    algorithm Calculate the average turnaround time for all

    processes

    Calculate the average waiting time for allprocesses

  • 8/13/2019 CSC520 Chapter 4 Exercise Solutions

    11/13

    P0 20 P1 45 P2 45 P3 50 P4 60 Average turnaround time 320/5 = 64 P0 0

    P1 10 P2 25 P3 35 P4 35 Average waiting time 105/5 = 21

    P0

    0 20

    P1

    55

    P2

    75

    P3

    90

    P4

    115

  • 8/13/2019 CSC520 Chapter 4 Exercise Solutions

    12/13

    Exercise

    Suppose a system uses RR (q =15) schedulingwhere a small integer means higher priority

    Create a Gantt chart to illustrate the execution of these processes

    What is the turnaround time for process P2 underRR scheduling?

    What is the average waiting time for theprocesses?

  • 8/13/2019 CSC520 Chapter 4 Exercise Solutions

    13/13

    P2 turnaround time = 25 Waiting time

    P0 25 + 35 + 20 + 15 + 5 = 100 P1 25 P2 15 P3 30 P4 10 + 20 + 15 + 15 = 60

    Average waiting time 230/5 = 46

    P0

    0 15

    P1

    30

    P2

    40

    P0

    55

    P1

    60

    P3

    75

    P4

    90

    P0

    105

    P3

    110

    P4

    125

    P0

    140

    P4

    140 155

    P0 P4

    170 175 180

    P0