CPU algorithms
CPU AlgorithmTurnaround time :- Amount of time to
execute a particular process.Waiting time – amount of time a process
has been waiting in the ready queueThroughput – No. of processes that
complete their execution per time unitAverage waiting time :- Average waiting
time of all the process
Criteria's to be usedTurnaround time = CPU Burst Time +
Waiting timeWaiting time = Turnaround time - CBTAverage waiting time= Waiting time / count
of total processesThroughput time = Total burst time / total
count of processes
ExampleProcess Burst time0 801 202 103 204 50
Gantt Chart
Turnaround time for process p3CPU burst time + waiting time
= 80 + 20 + 10 + 20= 130.
Waiting time for all the processesWaiting Time = Turnaround time – CBTFor p3
130 - 20 = 110
Waiting Time for process p0 = 0 sec.Waiting Time for process p1 = 80 sec.Waiting Time for process p2 = 100 sec.Waiting Time for process p3 = 110 sec.Waiting Time for process p4 = 130 sec.
Average waiting timeHence the average waiting time =
(0+80+100+110+130)/5= 84 ms.
Throughput timeThroughput time = Total burst time / total count
of processes
= 180/5= 36 Milliseconds
Example 2Process Burst time0 801 202 103 204 50
Arrival time = 0
Exercise Use SJF
Create a Gantt chart illustrating the execution of these processes?
What is the turnaround time for process p4?What is the average wait time for the
processes?
Gantt Chart
Turnaround time for process P4The turnaround time for process P4 is = 100.10+20+20+50
Average Waiting timeWaiting time of po+p1+p2+p3+p4(100+10+0+30+50)/5 = 38 ms
Example 3p CBT Arrival Time0 80 01 20 102 10 103 20 804 50 85
Draw gantt chart using SJF NON-Preemeptive
Excercisea. Suppose a system uses RR scheduling Quantum of 15 .Create a Gantt chart illustrating the execution
of theseprocesses?
b. What is the turnaround time for process p3?
c. What is the average wait time for the processes?
Gantt Chartp CBT Arrival Time0 80 01 20 102 10 103 20 804 50 85
Turnaround time for process P3The turnaround time for process P3 is =160-80= 80 sec.
Waiting timeWaiting time for process p0 = 0 sec.Waiting time for process p1 = 5 sec.Waiting time for process p2 = 20 sec.Waiting time for process p3 = 30 sec.Waiting time for process p4 =4 0 sec.
Average waiting timeaverage waiting time is (0+5+20+30+40)/5
= 22 sec.
Do it Yourselfp CBT priority Arrival Time0 80 0 01 20 10 02 10 10 03 20 80 04 50 85 0
Calculate turnaround time of p3 for FCFS, SJF, RR(Quantum =10), Priority
Waiting time for each process for each FCFS,SJF,RR,Priority