230 likes | 352 Views
CPU algorithms. CPU Algorithm. Turnaround time :- Amount of time to execute a particular process. Waiting time – amount of time a process has been waiting in the ready queue Throughput – No. of processes that complete their execution per time unit
E N D
CPU Algorithm • Turnaround time :- Amount of time to execute a particular process. • Waiting time – amount of time a process has been waiting in the ready queue • Throughput – No. of processes that complete their execution per time unit • Average waiting time :- Average waiting time of all the process
Criteria's to be used • Turnaround time = CPU Burst Time + Waiting time • Waiting time = Turnaround time - CBT • Average waiting time= Waiting time / count of total processes • Throughput time = Total burst time / total count of processes
Example Process Burst time 0 80 1 20 2 10 3 20 4 50
Turnaround time for process p3 CPU burst time + waiting time = 80 + 20 + 10 + 20 = 130.
Waiting time for all the processes • Waiting Time = Turnaround time – CBT • For 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 time • Hence the average waiting time = (0+80+100+110+130)/5 • = 84 ms.
Throughput time • Throughput time = Total burst time / total count of processes • = 180/5 • = 36 Milliseconds
Example 2 Process Burst time 0 80 1 20 2 10 3 20 4 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?
Turnaround time for process P4 • The turnaround time for process P4 is = 100. • 10+20+20+50
Average Waiting time • Waiting time of po+p1+p2+p3+p4 • (100+10+0+30+50)/5 = 38 ms
Example 3 p CBT Arrival Time 0 80 0 1 20 10 2 10 10 3 20 80 4 50 85 Draw gantt chart using SJF NON-Preemeptive
Excercise • a. Suppose a system uses RR scheduling Quantum of 15 . Create a Gantt chart illustrating the execution of these processes? • b. What is the turnaround time for process p3? • c. What is the average wait time for the processes?
Gantt Chart p CBT Arrival Time 0 80 0 1 20 10 2 10 10 3 20 80 4 50 85
Turnaround time for process P3 The turnaround time for process P3 is =160-80 = 80 sec.
Waiting time • Waiting 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 time • average waiting time is (0+5+20+30+40)/5 = 22 sec.
Do it Yourself p CBT priority Arrival Time 0 80 0 0 1 20 10 0 2 10 10 0 3 20 80 0 4 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