180 likes | 200 Views
Operating Systems AICT004-3-2. Process Control Management. Prepared by: Dhason. Topic & Structure of the lesson. Non-preemptive algorithms Calculations using non-preemptive scheduling algorithms. Learning Outcomes. At the end of this lecture YOU should be able to:
E N D
Operating Systems AICT004-3-2 Process Control Management Prepared by: Dhason
Topic & Structure of the lesson • Non-preemptive algorithms • Calculations using non-preemptive scheduling algorithms
Learning Outcomes • At the end of this lecture YOU should be able to: • - list non-preemptive scheduling algorithms • - perform calculations using non-preemptive • algorithms
Key Terms you must be able to use • If you have mastered this topic, you should be able to use the following terms correctly in your assignments and exams: • first come first serve / first in first out • shortest job first • priority
First Come First Serve ( FIFO / FCFS) • the simplest CPU scheduling non-preemptive algorithm • a process that requests for the CPU first is allocated • the CPU • the implementation of the FIFO policy is easily • managed with a FIFO queue • the average waiting time for FIFO is quite long • once the CPU has been allocated for the process, the • process keeps the CPU until termination or by • requesting for I/O
First Come First Serve ( FIFO / FCFS) Step1:- Draw a Gantt Chart to represent timings for all processes P2 P3 P4 P5 P1 19 14 0 13 10 11 Step2:- Calculate waiting time and average value TW(P1) = 0 TW(P2) = 10 TW(P3) = 11 Tw(P4) = 13 Tw(P5) = 14 TW(average)=( 0+10+11+13+14)/5 = 9.6 Milliseconds
First Come First Serve ( FIFO / FCFS) Step-3: Calculate turn-around time and average value P2 P3 P4 P5 P1 19 14 0 13 10 11 TT = Tw+TB TT(P1) =( 0 + 10) = 10 TT(P2) =( 10 + 1) = 11 TT(P3) =( 11 + 2) = 13 TT(P4) =(13 + 1) = 14 TT(P5) =(14 + 5) = 19 Average turn around time is (10+11+13+14+19)/5 = (67/5) =13.4 Milliseconds
Shortest Job First (SJF) • scheduling is done by examining the length of the next CPU burst of a process • if the CPU is free, the next process with the smallest CPU burst time is assigned • if two processes have the same CPU burst time, FIFO is used to break the tie • the difficulty with SJF is to determine the length of the next process • the advantage of this algorithm is that it is optimal; providing minimum average waiting time
Shortest Job First (SJF) Step1:- Draw a Gantt Chart to represent timings for all processes P2 P4 P3 P5 P1 Step2:- Calculate waiting times and average value TW(P1) = 9 TW(P2) = 0 TW(P3) = 2 Tw(P4) = 1 Tw(P5) = 4 TW(average) = ( 9+0+2+1+4)/5 = 3.2 Milliseconds 0 1 2 9 19 4
Shortest Job First (SJF) Step-3: Calculate turn-around time and average value TT = Tw+TB P2 P4 P3 P5 P1 0 1 2 9 19 4 TT(P1)=( 9 + 10)= 19 TT(P2)=( 0 + 1) = 1 TT(P3)=( 2 + 2) = 4 TT(P4)=(1 + 1) = 2 TT(P5)=(4 + 5) = 9 Average turn around time is (19+1+4+2+9)/5 = (35/5)=7 Milliseconds
Priority • priority is associated with each process • the CPU is allocated to a process with the highest priority • equal priority processes are scheduled using FIFO • priority can be high or low; however 0 can mean high priority • can be preemptive or non-preemptive • a problem with priority algorithm is starvation • aging is a technique used to gradually increase the priority • of a process
Priority Step1:- Draw a Gantt Chart to represent timings for all processes P4 P1 P3 P5 P2 1 13 0 11 18 19 Step2:- Calculate waiting time and average value TW(P1) = 1 TW(P2) = 18 TW(P3) = 11 Tw(P4) = 0 Tw(P5) = 13 TW(average)=(1+18+11+0+13)/5 = 8.6 Milliseconds
Priority Step-3: Calculate turn-around times and average value P4 P1 P3 P5 P2 1 13 0 11 18 19 TT = Tw+TB TT(P1)=(1+ 10)=11 TT(P2)=(18+1)=19 TT(P3)=(11+2)=13 TT(P4)=(0+1) =1 TT(P5)=(13+5)=18 Average turn around time is (11+19+13+1+18)/5 = (62/5) =12.4 Milliseconds
Quick Review Questions • Name three preemptive CPU scheduling algorithms • Which of the three is the easiest to implement?
Follow Up Assignment • FIFO on its own is a scheduling algorithm, however FIFO is also used in other algorithms, name the algorithms. • Which non-preemptive algorithm is optimal and why?
Summary of Main Teaching Points • Non-preemptive CPU scheduling algorithms are • FIFO, SJF and priority. • SJF algorithms have a shorter average waiting time • compared to FIFO and priority. • Using priority scheduling may result in some processes • experiencing starvation; aging a method to overcome this • problem.