Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
197 views
Unit 2
Fundamentals of CPU scheduling
Uploaded by
Arjun Choudhary
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save unit2 For Later
Download
Save
Save unit2 For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
197 views
Unit 2
Fundamentals of CPU scheduling
Uploaded by
Arjun Choudhary
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save unit2 For Later
Carousel Previous
Carousel Next
Save
Save unit2 For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 52
Search
Fullscreen
Qy a2 as a4 as a6 a7 as WU-BSC-Comp) 523 Process SYNhrenizay, ‘okay ot noth Fig. 592 3 The waiting queue contains processes that have been awakened by notify operation. Each monitor has one waiting queue. 4. Condition variable queues contain processes that have executed a condition variable wait operation. There is one queue for each condition variable. ‘The queues associated with a monitor does not have a signaller queue. when the active process executes a wait or leaves the monitor the lock becomes available Explain Genoral structure ofa typical process Explain in beet The Critcal-Secton Problem Explain algorithm for ertical section problem Explain Classic Problems of Synchronization What is Peterson's Solution ? Write a short note on Monitors \Wiite a short note on Semaphores. Define : (1) Cooperating process (2). Independent process (3) Race condition (4) Critical section (5) Semaphore ‘What are the requirements of solution the critical-section problem ? goo COPAY DLS University reseed Sys save Cort, Seething Cita, Sans PS aa a lg Ane (Fors, sur, saTF, The Sean, 6.1 CPU Scheduling 5 __ What is mean by CPU Scheduling? = Itis a process that allows one process to. : : se te CPU we he exe another procs is onl te orang ede eee ‘resources, thereby making full use of CPU. CPU ‘scheduling is to ae ‘he system efficient, fast and fair, ito sin the - For example, consider process A and process B , Process i : Pres Ais ng inl ‘state because of unavailability of resources like /O devices at that time Pres Bismaking fill te of CPU. | 6.2 Basic Concepts (2) Running process all time for maximum CPU utilization obtained with ‘multiprogramming. (2) Scheduling is function of Operating System. (3) «The task of selecting the process in memory that are ready to execute and allocating them to the CPU is performed by the CPU Scheduler (4) CPU-1/O Burst Cycle - Process execution consists of « cycle of CPU execution and LO wait. CPU Burst Cycle consists of arithmetic operations(addition subtraction etc) instructions and it data can transfer from main memorywo ©) ©) System (MU-BSC-Com) 62 SPU Sched to internal register, these instructions are executed by Only CPU, s0 the, require very less amount of time for executions. = VO Burst Cycle consists of read and write operations. ~ It transfer a data from input device to main memory or internal register of the CPU know as read operation and transfer data from main memory or internal register of the CPU to Output device known as write operation. ~ Instructions are executed by CPU with VO devices so it required very large amount of time for executions. ‘Read A ] 10 Burst Instructions Read B ‘AddA | CPU Burst Instructions Add B Print C | 10 Burst Instructions CPU burst distribution : Performing calculations, and. An UO burst, waiting for data transfer in or out of the system. CPU Scheduler means CPU scheduling decision may take place when a Process switches from running to waiting state, switches from running to ready state, switches ‘rom waiting to ready and terminates CPU Scheduler. (A) Non-Pre-emptive scheduling : In this type of scheduling once CPU is allocated to any process it never bring to a halt or pre empted till the ‘current process is not finished its execut Advantages () Sometime it supports multiprogramming. (2) Waiting time of process is less. (8) Context switching time is not required. Disadvantages (D) Deadlock occurred. (2) Average turnaround time is more. (8) Degree of multiprogramming decreases. (®) Pre-emptive scheduling : In this type of scheduling once CPU is allocated to any process then it bring to a halt executions of the current process because of some another higher priority process comes for execution. Advantages (2) It supports multiprogramming. (2) Deadlock does not occurred. i EF operating Systm (MU-BSC-Cong) a Disadvantages = Fig. 62.1; CPU Burst Dist * Process A ool ws wt lew = =e = ee a Po wre totle Pent vat) Obit a ee com era fom She CPU burst se ~- |. ma ot | WObust Fig. 6.2.2: CPU-UO Burst Cycle 2016.& (wu-asc-cong) 4 a Brac 6.3 Scheduling Criterla EaF_Explain the scheduling citera? Following are different criteria to check when considering the "best" scheduting algorithm : (1) cPUutiization Tt is a best use of CPU, CPU would be working most of the time 100% then thy algorithm is called very good best algorithm. @) Load average It is the average number of processes resides in the ready queue and it ig ‘waiting for their turn to get into the CPU. (8) Response time tis an amount of time that takes from when a request was submitted until the first response is produced. (4) Throughput The total number of processes completed per unit time. Its range varies from ‘0/second to hour and it depends on process. (6) Turnaround the It is the amount of time taken to execute a particular given process. The ‘amount of time between submission of the process and completion of the Process. (©) Watting ume ‘The computat of the waiting time of process spent in the ready queue. Note ‘that CPU utilization and Throughput are maximized where as another factor are reduced for proper optimization [64 Scheduling Algorithms Following are types of scheduling algorithm (1) FOFS (First Come First Serve) (2) SIF Shortest Job First) ae EF coring Som M986 Conp ts ru (9) SRIF (Smallest Reming Tine Fn) (a) Priority (6) BR (Round Robin) (6) Multilevel Queue Scheduling (2) Maltlovel Feedback Queve Scheduling 6A.1_FOFS (Fist Come Fist Sere) Scheduing Algor _Explain FOFS CPU Schedullngsgoritim, arrive in the ready queve for execution, In this, the process that comes firs wll be executed . executed first and next process only after the previous proces finished its extn, Pros tarts In this algorithm select proces for execution wh is . ose arrival time is emall or who comes first for execution then selected prors is abated oP = This algorithm only returns process number who comes frat in to’ the - Once process stats its execution it shoud no stops it execution unt it finished its execution. Hence ths algorithm is Non Preemptive Sebedeling Algom ‘Algorithm Consider, m: It is total number of process in ready queue, ‘Smallest_arrival_time: Its a smallest arrival time. ‘Az Ttis an array, and store arival time, burs time, PIDProcess identification Numer) of every process Step 1: Let n = Number of processes in ready queue. Step 2: ‘Smallest_arrival_time: Step 3: if Smllest arrival. then Smallest_arrival_time=A(K] Arrival. time Go to step 5 else Goto step 4 e>AIKT LOVES EAS SO& (uu.85¢-Coro) es or Step 4: pores Step: ifAcn then Goto steps else Gota steps Find out process whose arrival time = smallest arrival time iftmore than such process are available then Goto step 8 else ‘Return Process number to dispatcher Step 8: Find out srallest Process Identification Number (PID) from processes why hhas same arrival time, Step 9: ‘Send selected process number to dispatcher for execution. Advantages (1) Easy to understand and implement. (2) Not required any priority. (3) Require queue to implement so it is sufficient for FCFS. Disadvantages (Very oor CPU wiliztion (2) Last process waiting time is very high. Example 6417 Conair faloving eat of procassos with length of CPU Aral tie ard burt me given in milssconde Process | Arrival tine | Burat time Pi 1 2 v2] a ¢ ro f 6 lutea the exection of these us alportm. Calcst wat tne, average walle and tum around ‘erage tum around ine of each process also craw tre Gait Chat, Bh cpemmseemussccm a, cou ution: Sell ph, P2, PB are the process, ‘arrival time is time at which proces i p30 which is given Burst times the total time required fr Start time is a time at which process starts, of process. Pl=2, P2=4, P3=6 Start time of first process is its arival time, rn for start time of process, Pi=p Here Po arrival time i _ Start time of other process is calculated by ado, of previous process. of start time and burst time Finish time is calculated by addition of start ‘ime and burst time of that process. = Wait time of every process is calculated by subtract 5 . time of that process. of start time and arrival ‘Average wait time is calculated by average of wait time of all around time of every proces is casted by mbtracon of haat ane wok arrival time of that process, = Average turn around time is calculated by average of turn around time of all processes, Process | Arrival | Burst | Start] Wait. | Finish | Tarmaround ‘Name | time | time | time| time | time as (ran | eran | ran PL 1 2 [6 5 8 Fi P2 2 a [3 6 Ps ° e [oe ° 6 5 ‘Total wait ‘Total turn time=11 around time = 23 ‘Now ,Total wait time = 11ms ‘Total turn around time = 23ms Average wait time = 11/3 = 3.66ms Average turn around time = 2/3 = 7.86ms ‘Throughput 3 jobs/12 sec = 0.25 jobalseecru PEF operating Systm M-9S0-Com) £8 Se Gantt Chart (3 [| | 8. 2 arr inal ive p esas with length of CPU Arrival time ang Example 642: Consider following set of procs burst time given in miliseconds Process | Arrival time | Burst time Pi o 24 P2 0 3 PS © 3 strate the execution ofthese process using FOFS scheduling algorithm, ‘Coluate wait time, average walt time and tum around time, average tum ‘around time of each process also draw the Gantt Chart Solution : - PI, P2, P3 are the process. - Arrival time is time at which process is P3.=0 which is given. — Burst time is the total time required for execution of process. P3 = 8, Start time is a time at which process starts it execution. Start time of first process is its arrival time. Here P1's arrival time is selected for start time of process. Pl = 0. ‘Start time of other process is calculated by addition of start time and burst time of previous process. Finish time is calculated by addition of start time and burst time of that submitted into a queue. Pl = 0, P2=0, PL= 24, P2=3, Process. = Wait time of every process is calculated by subtraction of start time and arrival time of that process. - Average wait time is calculated by average of wait time of all processes, Turn ‘around time of every process is calculated by subtraction of finish time and arrival time of that process. - Average turn around time is calculated by average of turn around time of all Processes. bbb NAAN STAM Ge ra BF posi som (MU-BSC-Comy ei oP ‘Arrival | Burst | Start 88 We P ei time | time | time | att@® | Finish [Turn around Ns TAT) |. time thme Peto tm Pe Te te 24 co 0 Sj 4m 24 27 21 a Sj | | a ® Total wait Total tum ‘time=51 aaa times61 en around tse = 6100 average wait time=5U3 = 17ms ‘rerage turn around time = 81/8 = 27ms ‘Throughput 13 jobs/30 see = 0.1 jobalsce Gantt Chart pi pm | vs ° 4 30 Frample 643: Consider folowing set of processes with length of CPU Aival mo and burst time given in millseconds Process | Arrival time | Burst time Pi 0 4 P2 1 2 3 2 1 Pa 3 2 PS 4 5 itustrato the execution ofthese process using FCFS scheduling algortnn. Cansatate watt imo, average wat ime and tu around tine, average tm Sround time of each process also draw the Gantt Cart Solution = = PI, P2, P3, P4, PS are the processes. = Arrival time is time at which process is submitted into aquene; i 2016- , Pa = 9, PS=4 which i given P1=0,P2=1,P3=BB cenmpgeenaosccon) 60 eed Burst time is the total time required for exceution of process, Pied, P2=3,P3= 1,P4 = 2,P5 =5 ‘Start time is a time at which process starts it execution. ‘Start time of first process is its arrival time, Here P1's arrival time is selectey for start time of process. P1=0. ‘Start time of other process is calculated by addition of start time and burst tim of previous process. Finish time is calculated by addition of start time and burst time of thee process. ~ Wait time of every process is caleulated by subtraction of start time and arriya) time of that process. ~ Average wait time is calculated by average of wait time of all processes, ‘Dury ‘around time of every process is calculated by subtraction of finish time ang arrival time of that process. ~ Average turn around time is calculated by average of turn around time of al) processes. ‘Process | Arrival | Buret | Start | Waittime | Finish | Turn, Name | time | time | time | (sT-AT) | time | around time wren | TAT PL 0 4 0 ° 4 P2 1 3 4 3 6 3 2 1 7 5 6 P4 3 2 3 5 7 PS. 4 5 10 6 u u ‘Total wait ‘Total turn i around time= 34 ‘Now, Total wait time = 19ms ‘Total turn around time = 34ms Average wait time = 19/5 = 3.8ms Average turn around time = 34/5 = 6.8ms ‘Throughput 5 jobs/15 sec = 0.33 jabs/see a — ing Systor (MU. ou cpu Gantt chart n mj mo Tm Dw ° 4 5 8 6.42 SUF (Shorte: J0b Fiat) Scheduiing Algortnm 16 ga _ Explain SJF CPU Scheduling algorithm, ‘Non Pre-emptive S3F scheduling algorithm Pre-emptive SIF scheduling algorithm 1. Non Pre-emptive SUF scheduling algorithm 5 _ Explain Non Preemptive SJF acheduling algorithm, - | In this algorithm when CPU is executing any process and during it execution if any higher priority process is entered in ready queue then it will not stop its current execution until it finish it. It completes its current execution first and then considers priority process. (Shortest duration process). - If smallest burst time of two processes is same as well as arrival time of both process ‘is same then selection for execution is depends on their Process Tdentification Number (PID) Algorithm, Consider, n: It is total number of process in ready queue. ‘Smallest_burst_time : itis a smallest burst time. ‘A: It is an array,and store arrival time, burst time, PID(Process Identification Number) of every process Step 1: Let n=Number of processes in ready queue. Step 2: ‘Smallest_burstl_time=1 :K=2 2 | g-4-S Step 3: Step 4: Step 5: Step 8: Sept 9: Step 10: Step 11: CPU Sched tom (U-850-Co) 2 if Smllest_burst_time >AIK] then ‘Smallest_burst_time=A(K].burst_time Goto step 5 else Goto step 4 AzAtL Aa then Goto step3 else Return Smillest_burst_time Find out process whose arrival time = smallest burst time if more than such process are available then Go to step 8 else Return Process number to dispatcher | ‘Find out smallest arrival time process from smallest duration processes. iftmore than such processes are available then Goto step else Return process number to dispatcher ‘Find out smallest identification number from shortest duration processes. Send selected process number to dispatcher for execution. B opratna ystom (MU-BSC-Comg) a cpu iaavantage? (a) Simple to implement, fo) Good CPU uilization fe) _Biiieney of process increased, pisadvantages (a) Duetolong eae Waiting time of some processes ae high, {@) Does not provide priority to process, jo644; Consider following set of Bane Consider folowing St ot processes with length of CPU Arial tne and Pt 1 a P2 2 2 PS ° 5 lMustrate the execution of these process using Non pre-emptive scheduling ljortn. Calle wah tre, avg, wat tne ae um around ie, average tm ad tec ech proces aad Be art solution: Pi, P2, P3 are the process. Arrival time is time at which process is submitted info a queue. Piel, P2=2, ‘P3=0 which is given. Burst time is the total time required for execution of process. P1=3, P2=2, P3=5. Start time is a time at which process starts it execution. Start time of first process is its arrival time, Here PS's arrival time is selected for start time of process. P3: Start time of other process calculated by addition of start time and burst time of previous process. In Non pr-emptive SUF select first process for execution do the following steps Find out smallest arrival time and consider: ‘it as a current time. Find out smallest duration process up to this current time using burst time, arrival time and PID. - Finish time is calculated by addition of start time and process. > Frc tame of evry process i allt by subtraction of start time and arrival time of that process. 20 18- ‘burst time of that A-!PE ovoratng tem u.8sc-comp) 64 CRU Seta ~ Average wait time is calculated by average of wait time of all processes. Ty around time of every arrival time of that process. process is caleulated by subtraction of finish time ang ‘Average tum around time is ealculated by average of turn around time of ay i nN neni ea solutio i PI, P2, P3,P4 are the processes, processes. Process | Arrival | Burst | Start] Wait | Finish [Turn aroung Name | time | time | time | time | time time a eran | erBn | eran __ Start time is a time at which proces saris PL 1 7 6 10 9 proces is ie arrival time, Here PBs anal ine eens ie of Bt = 3 i 3 a 3 ; pets Pt 5 start time of _ Start time of other process is calculated wm toe fs | o | 0 5 5 a by adtin of tar tine and burst ine Total wait Total tum In Non premptive SIP elect first proces fr eeu he lowing tap around Jo the flowing steps: Find outsm val ti : paar ea rere i td ener itasa caret tine ars ° fout smallest duration process up to this : Now ay time, arrival time and PID, cee ‘Total turn around time =19ms " _ Finish time is calculated by nade Average wait time= 9/3 = 3ms am °y addition of start time and burst time of that Average Turn around time = 19/9 = 6.33ms Wait time of every proces is calculated by subtraction of start time and arrival ‘Throughput time of that process. 8 jobs/10 see = 0.3 joba/see “Average wait time is caleulated by average of wait time of all processes, Turn Gantt Chart around time of every process is calculated by subtraction of nish time and arrival time ofthat process. ps | me | pt a ree area a et eed by eee es tore ee ° 5 7 10 processes. Example 645: Consider folowing set of processes with length of OPU Arrival tine and Process | Arrival | Burst | Start | Waittime | Finish | Tura around burst time given in miliseconds fame | time. | time | time | gt: time | time AT) Process | Arrival time | Burst time isrven | onan Pi ° 6 PL 6 o | 3 3 @ @ P2 0 8 P2 8 o | «| ey 24 B o 7 5 Fi ole 1.8 16 16 3 P4 3 oO o ° 3 3. lustrate the execution of these process using Non pre-emptive SUF ‘Total wait ‘otal turn scheduling algorthm Calculate wait time, average wait time and tum time=28 around around time, average tum around me of each process also draw the Gant a teppei Chart PEELE —eS e16 i BB oncmpgoemntasecory) i SPS Now, Total wait time = 28ms ‘Total turn around time = 52s Average wait time = 28/4 = 7ms Average Tam around time = 52/4 = 13ms Throughput 4 jobs!24 see = 0.25 jobs/see Gantt chart Pa pi_| Ps P2 0 3 9 16 24 2. Preemptive SJF scheduling algorithm E&_ Explain Pre-emptive SJF scheduling algorithm, In this algorithm when CPU is executing any process and during it execution ig any higher priority process is entered in ready queue then it wil stops the ‘current execution of process and select higher priority based process for execution, If smallest burst time of two processes are same then it select process from ‘smallest arrival time and if smallest burst time is same as well as arrival time of both process is same then selection is based on Process Identification Number em). Algorithm 3 Consider tis total number of process in ready queue. ‘Smallest, burst.time : itis a smallest burst time. ‘A: It is an array and store arrival time, burst, time, PID(Process identification Numer) of every process Step 1: Find out smallest buirst time process Step2: Select process who has smallest burst time Steps: During execution of process if any smaller duration process is entered into ready queue then Cee cana itera Call dispatcher for stop the cure Goto stop? execution of process else Continue current process exeetion (2) Simple to implement, (2) Good CPU utilization. (@) Efficiency of process is increased, Disadvantage (1) Tum around time of process is increased, Example 6a Consie ehowng coro burst tim given in miiseceeas nS Wt lah of CPU Arial Gime and Process | Arrival timo Pt 1 P2 2 Pa ° Burt tine 3 2 5 Mustrate the execution of these process scheduling ‘Cacdos wines 8 Now peromptie SIF ‘verge around tie, aeagetumarantne soc sa os at a Solution = P1,P2, P3 are the prosest ‘Arrival time is time at which process is submitted into a queuePlel, P2=2, 320 which is given. ‘Burst time is the total time required for execution of process. Pl=2, P2=9, P2=5. Start time is a time at which process starts it execution. Start time of first process is its arrival time, Here P3's arrival time is selected {for start time of process. P3=0 Start time of other process is calculated by addition of start time and burst time of previous process. In pre-emptive SJP selec first process for execution do the following steps find ‘out smallest arrival time and consider it as a current time find out smallest duration process up to this current time using burst time, arrival time and PID 26hFinish time is calculated by addition of start time and burst time of tha, Process. Wait time of every process is time of that process. If the process is pre-empted because of higher priority process then it also agg total time spent in the ready queue. In this example process PS arrives at 0 calculated by subtraction of start time and arriygy and executing up to 1 because of higher priority process Pl comes in ready queue [P1 needs 2 burst time and PS needs 4 burst time } so P3 goes into ready queue again so wait time of P9 is caleulateq Wait time = (Start time - Arrival time)+(new start time ~ old finish time) so olg finish time = 1 and new start time = 6 Wait time = (0 - 0}+(6-1)=5 ‘Average wait time is calculated by average of wait time of all processes, ‘Turn around time of every process is calculated by subtraction of finish time and arrival time of that process average turn around time is calculated by average of turn around time of all processes. EF poring system WSCC) a 4.3 SATF Scheduling Algorithm ‘This scheduling process with smallest amount of im executing process is the one with shortest remainin ey that time should only reduces exe: asta an nee y complete oF new process is added that required anallerrment g Disadvantages time, © Processes with long CPU times will always have to wat processes keep arriving. to wait as newer Impossible to predict how long a process wil take as we 5 keep getting moved off and on the CPU, 8 we don't know if it will Process | Arrival| Burst | Start | Wait time Finish | Turn around Name | time | time | time | (sT-aT) "| time fine (STBD) | TAD | PL 2 1 o 3 2 P2 2 3 3 1 6 4 P3 5 0 (0 -0)+(6-1)=5 10 10 ‘Total wait ‘Total turn time=6 around time=20 Average wait time = 63 = 2 ms Average turn around time = 20/3 = 6,66 ms pa [ pif pe | ps o 1 3 6 10 ‘Throughput 3 jobs/10 sec = 0.3 jobs/sec Zrample GAT: Consider folowing et of presses wi ong : burst time given in milliseconds “ ory ome od Process | Arrival time | Burst time Pr 0 7 Pa 1 5 Pa. 2 3 Pa 3 1 PS 4 2 P6 5 1 Iustrate the execution of these process using SRTF scheduling algothm. Calculate wait time, average wat time and tum around time, average tum ‘around time of each process also draw the Gantt Chart Solutio - PI,P2, P3, P4, P5, PG are the processes. = Arrival time is time at which process is submitted into a queue. P1=0, P2=1, P3=2, P4=3, P5=4, P6=6 which is given burst time isthe total time required for execution of process. P1=7, P2=5, P3=3, P4=1, P5=2, P6=1. = Start time is a time at which process starts it execution. Start time of Bist process is its arrival time. Here P's arrival time is selected for start time of process. P1=0. Zeer — |cpu, eS on (MU se . ution of start time and Durty Star tine of other rec for execution do the tlw ‘previous process. s surrent time val time and consierit a5 20 stops find out smallest arrival time rte procst £63800 a 7 is dit directly not ; a “a a ee ck at time which antBer roca available for execution. ‘Once one unit time executi Consider P1 Burst time = remaining burst time is 7~ 6 ‘After one unit time is executed for arrived ie. arrival time = 1. | Hee yal dig «1 Process P2 as arrival ime = 1 hence selec ta, aon aa pat Unit and check te remaining buret time 6-1 = 4) In This way all press is executed til eomplete its execution Finish time iy calculated by addition of start time and burst time: of that process. Wait time of every process is calculated by subtraction of start time and artim time of that process “Average wait time ia clcalated by average of wait time ofall processes, Tun rend tine of every process is calculated by subtraction of finish time ang arrival time of that process. ‘Average turn aroued time is calculated by average of turn around time of al) sining burst time is executed, ion is done rem : fed 1 Unit time and stop it beng! 750 it is execut Process Pi check at time 1 which proce, Wait time Sis _lersn | eran: PL ° 1 0 12 9 19 P2 1 5 1 7 13 12 Pa 2 3 2 1 6 4 P4 3 1 3 0 4 1 ad if 2 1 3 8 5 76. 6 1 6 1 7 2 Total wait Total turn time=24 a time=43 rating System (MU-BSC-Comp) tei ie ‘Some time process required to run first even if they are come late in ready o are come late queue or required long duration of CPU for execution, CPU is located tothe ‘process with highest priority so provide priority number to that proces so it can ~osily select higher priority process for execution. If Processes are same priority then it executed in FCFS manner. Priority is decided based on memory requirements, time requirements, or any other resource requirement. Following are two types of Priority Scheduling : (4) _ Non Pre-emptive Priority Scheduling algorithm (2) Pre-emptive Priority Scheduling algorithm Non pre-emptive priority scheduling algorithm cipal Nou pea Sune srecxting any process and during it execution if tered in ready queue then it will not stop its Tt completes its current execution first and In this algorithm when CPU is « any higher priority process is ent current execution until it finish it. then considers priority process. If priority of two process are same then it time. {f smallest arrival time of both proses is also same then on their Process Identification Number(PID) selects process from smallest arrival selection ean depend DO) Mcrae 5sing json i 880-Gg S ' oz ete, omaaamemanesecrny pests a solution Biep ai = PI, P2, P3 are the process. Rind out highest priority process from ready queue. = Arsival time is time at which process is aubmittd int a queve, Plc, Poe, Step 2: ‘P30 which is given. ifmore than such processes are available = Burst time is the total time required for execution of proces, Ple2, Pet, Foa6 Kos | ut time isa tine at which presi sera te wees eee ee Goto step 3 process is its arrival time. Here P3's arrival time is selected for start time of tee recesP ‘Return Process number to dispatcher. _ Start time of other process is calculated by addition of start time and burst time Steps: of previous process. Find out smallest arrival time process from highest priority processes — In Non pr-emptive Priority select frst process for execution do the following supa: | " ope: Smee than sch proc areaale o° lad out cast aire isa ude fsa cin tina Go to step 5 o Find out highest priority process, priority of the number of process here os High pty ron Ft hth inghen a pobien F- Return process number to dispatcher ‘ - Finish time is calculated by addition of start time and burst time of that steps: : ee : Find smallest PID from same priority process = Wait time of every process is calculated by subtraction of start time and arrival Stepe: j time of that process Send this process number to dispatcher — Average wait time is caleulated by average of wait time of all processes. Advantages = Turn around time of every process is caleulated by subtraction of finish time and (2) Good CPU utilization. arrival time of that process. (2) Efficiency of process is increased, = Average turn around time is calculated by average of turn around time of all Disadvantages processes. (Q) Waiting time of lowest priority processes are Process | Arrival | Burst | priority | Start | Wait ve priority, ry high because of higher ‘Name. timer time "anes {2)__Turn around time of lowest priority processes is very long. ese PGe a Agee Example 6.48: Consider folowing set of of 6 | 7 Dustin Snares "kre OPA ad mfr 2 tania Process | arrival time’ | Burt time | peony] 5 a 5 1 0 0 PL 1 oe (highest) wait Pa 2 4 5 time=I3 a a) it Ikstat be exon EIT SO ANON,SSO Nene eR 3 CSR SS ia mi asco eee Sey opemommmwascere ty venning “nen Pa P5 PL P38 Pa seen: Send this process identificati is a i 6 re ee) step: ‘Se mumber to dispatcher and goto step 7 tae a ceed ty ee if yes then call dispatcher to stop current process execution and stats new process execution, {EF __ Explain pro-emplive priority scheduling algorithm \ Tn this algorithm when CPU is executing any process and during execution if any higher priority process is entered in ready queue then it iff no then Continue till execution of current proces is not finished and then go ‘will stops the current execution of process and select higher priority based to step 1 again. process for execution: ae aan i a then it selects process from smallest (0) Good CPU utilization. (2) Efficiency process is increased. —- ‘If smallest arrival time of both process is also same then selection can depend on there Process Identification NumberPID) Disadvantages (1) Waiting time of lowest priority processes are very high because of higher ee a Btep i an priority process. Tum around tis fori ia Find higher priority process from ready queue @ d time of lowest priority processes is very long. Step 2: Example 6.4.11 Conniser shoring set of ose with length of CPU Arrival time and ~ ‘ifmore than such processes are available at tp given i enccne then Process | Arrival time | Burst time | Priorty Goto step 3 PI 1 3: __| sthighest) else P2. 2 2 2 ‘Return process number to dispatcher and go to step 7 - Pa f 5 4 Steps: llustrate the execution of aa ee ete tease i ‘ - a i Calcul ime, averag il Find out smallest arrival time process with higher priority process Seheduing alort erioundtime each process also draw the Gant Step 4: Chart % ‘ifmore than such process available Solution then ~ PL, P2,P9 are the process. Goto step 5 = Arrival time is time at which proces is submitted into a queue Pl=1,P2-2,P9-0 else which is give . PE pas Return process number to dispatcher and go to step 7 ~ Burst time is the total time required for exceution of protest, PICS.P2 Step 5: Start time is time at whith poet stats ik tn ical - ‘ 5 , Here P3's arrival time is selected Find out smallest process identification number form FIFO manner and high Start time of first process is its arrival time ei for start time of process. P3=0. 20 ea * Priority process.628 CPU Scheduling 3m (MU Star time of otber process is caleulated by dition of start time and burst time of previous process. In pre-emptive Priority select first 1. Find out smallest arrival time an 2 Find out highest priority process suing priority of the number of process here High priority process is Pl which is given P1=3. Funth time is ealelated by addition of start time and burst time of tht | | prvcens i | process for execution do the following steps d consider it as a current time. Tre tne of every process i calculated by subtraction of start time and arzival time ofthat process. Average wait time is = Tumaround time of every arrival time of that process. «Average turn around time is calculated by average of turn around time of all calculated by average of wait time ofall processes. process is caleulated by subtraction of finish time and Start | Wait | Finish [~ Turn time | time | time | around Gran |(sTsBD | time TAT) 0 4 3 4 2 6 4 0 | oxen | 10 10 5 Total Total wait turn time=7 around time=17 ‘Now, Total wait time = 7ms ‘otal turn around time = 17ms ‘Average wait time =7/3 ‘Average tum around time = 17/3 = 6.66ms ‘Throughput 3 jobv/10 see = 0.3 jobs/see P vi [ pe | ps ° 1 4 6 10 eee By conta mv ss0cor a5 AR (Round Robin) Scheduling Algorithm & 20 CPU Scheduli Ga _aplain RA Scheduling algorithm with example, 5 TRound Robin Scheduling is designed specially for time ‘used by CPU during execution ofthe eee rane beth Hea itis similar to FCPS scheduling algorithm bu the functionally of pre emption is ae added to switch between the processes. Soit is called as pre-emptive FIFO Jn this scheduler divide execution time into fixed small unit slices called as ‘Time Quantum (T.Q) A small unt of time also known as time slice This time slots assign to each processes which are present in ready queve and txseutes process within that slots only. Te RR it maintain ready queue and itis works as circular queve. Hence all RR CPU Scheduling algorithm are kept in the circular queve. In ach new process is added tothe tail of the maintained ready processes in RR algorithm e: queue. = By using this algor process in equal portions and in eireular any priority . In RR dispatcher work as follows : ‘Store old content of internal register, rithm, CPU makes sure, time slices are assigned to each order , dealing with all process without ° program counter and current resource status in the PCB : tion from ready queue. © Find new process for execut .d internal register from PCB of © Reload content into program counter an the new process © Start new process © Update remaining process. tharat time, new start time, total wait time of old ‘Advantages = Round Robin algorithm is starva = very process will be executed by time slice). So in this way no Proeess the OPU, Round robin algorithm is simple tion roe a compare to FOFS ‘CPU for fixed interel of time (which = 650% eft waiting for its tu ‘and easy to implement. 1m to be executed by ue 20)~ Start time of first process is its arrival time. Here P1’s arrival time i Boon geen msssccony) 90 Algorithm Step 1: Decides time quantum Consider T.Q. =1 Step 2: Select process from ready queve Step3: Call dispatcher for storing content of current process to PCB to old proces, Reload new process from PCB and update burst time, now start time of old process. Stop 4: Start new proces ill time quantum is not over Stop 5: Iftime quantum is over then go to step 2 ‘Advantage System efficiency increased. Example 64:11 Consider folowing sat of processes with length of CPU Arrival time and burt time given in illseconds [Process | arrival time | Burst time [er 0 24 [re o 3 [3 ° 3 itustate the execution of these process using AR scheduling algorithm. Calculate wat ime, average wait time and tum around time, average tum around tine of each process also draw the Gantt Chart .Consier Time quantum = 4 Solution: ‘Time quantum = 4 which is given in problem. P1, P2, P3 are the process. Arrival time is time at which process is submitted into a queue. P P8=0 which is given burst time is the total time required for execu! process, Pl=24, P2=3, P3=3. Start time is a time at which process starts i ‘execution. is selected {or start time of process. Pl=0 (All processes are arrived at same time 0 RR based on FCFS so select first process P1) P20, tion of Fh omampspien asec) ex CPU Sched Start time of other proces is calculated by addition of start tine and bur! and burst time of previous process Ja RR very process is excite only duit ine quantum end then ew proces ia selected and exceuted for same given ti iid given time quantum. Hore PI is executed to start time of P is 0. fester specie Bee Once any process is executing tis ti ime quantum remaining burs caluatd. Example IfPUs Bus tine =2anditenente¢ Gone Ok remaining Burst time is 24-4 -20 in this way proces is exerted ™ Finish time is calculated by addition of start time and bunt time of that process. Wait time of every process is caleulated by subtraction of start time and arrival time of that process. Average wait time is calculated by average of wait time of all processes. ‘Tum around time of every process is calculated by subtraction of finish time and arrival time of that process. Average turn around time is calculated by average of tur around time of all proceases Process | Arrival | Burst | Start | Walttime | Finish’ |) (Turn ~ Name | Mime | time | time | (eran, | sine | around time a ui — | GTB) (FT-AT) PL o>u lof. 30 0 P2 ops f«] 4 7 7 Pa pe Seema | ee 70 0 Teal walk Teal arm time=17 around tineet? Now, Total wait time = 17ms ‘Total turn around time = 47ms Average wait time = 17/9 = 5.66ms Average turn around time = 47/3 = 16.66ms Throughput 3 jobs/30 sec = 0.1 jobs/see pry pe | ps | PE . 4 7 1wo 1.B5C-Coro) ee CPU Sched, 6.4.6 Multilevel Queue Scheduling Algorithm ‘Ew Explain Multilevel Queue Scheduling. Processes are easily classified ito different groups multilevel queue scheduling is ereated two types of processes handled by operating system as : Foreground Process and Background Process. 1. Foreground Processes : These processes are interactive processes, Background Processes : These processes are used as offline processes and activated by request of the foreground processes. Following are characteristics of multilevel queue scheduling : ‘© Based on their type Processes are divided into different queue. © Processes are permanently assigned to one queue. 0 It allocates separate queue for each type of processes, It assign priority to each queue. o_ Itassign separate duration time quantum to each queue. ©" Bach queue has its own scheduling algorithm. o There must be scheduling among the queue. © It is implemented as priority preemptive scheduling algorithm Foreground process have higher priority than background, © No another process in the batch queue could rin unless the queue for system processes and interactive processes were all empty. If an interactive process enters the ready queue while a batch process was running, the batch would be pre-empted. Algorithm is divided into five categories as: () System Process 2) Interactive Process (8) Interactive Edit Process (4) Batch Process (6) User Process sing Spon 850 ne Eh crostna synumu-esccore) ess crusty Highest pony, Spenpeme iS) Lowest pity, i i Tug Fig. 64.1 6.4.7 Multilevel Feedback Queues Scheduling Algorithm EF _Explain multilevel feedback queues scheduling algorithm. ‘This scheduling algorithm allows a process to move between queues and has {following design requirements and parameters for multimode systems : Requirement ~ It give preference to short jobs. =. It give preference to HO bound processes. — Tedo Separate processes into categories based on their need forthe Processor. Parameters ~ Number of queu = Scheduling algorithm for each queue. ~ Method used to determine: ‘when to upgrade a process to higher priority queue priority queue © When to demote a process to @ lover! sets uerice © which queue a process wil enter when that ries aca CPU time. = Te will be moved to a lower-priority ques ite Pee uee oa . Tn the higher priority queves It eaves UO-Emund #1 WAT ved, to 8 = A process which waits too long with lower priority ane ‘ higher-priority queue, and prevents aor 20 [Omeeq aE ; wus oss ous El cpeningsysomwssecony <= 1. ote threads cee Stig Maltpe threads execton ona singh cPUw enable threat, Intieed scheduling following condons srw; 1. A higher priority thread becomes runnable, Tehas run method ext On systems that support time-slicing, its time allotment has expired its time allotment has Anigher priority thread becomes runnable. | Fig. 642 a | = Asshown in Fig. 6.4.2, there are three queues, numbered frvin PO to P2. ~ In this technique the scheduler first executes all processes in queue. ~ _ Ityields, or its ran method exits - When queue PO is empty it executes processes in queue PL. On systems that support time-slcing, its time allotment has expired. |= hen gues P0 and Pare empty the eects prc evasble in quae [66 _ GPU Schedng Examples | P2 will only. : i : ; - pe siancheread for acre ‘will preempt a pee ss in queue P2. Then process 1. FCFS: Examples in is preempted by a process arriving for queue PO. P Example 6.6.1: Concidor folowing set of processes with length of CPU Arial tina and = A process entering the ready queue is placed in queue PO. And available process " buratine gen amilesenge 7 {in queue PO is assign given a time quantum of 8 milliseconds. Iustrate the execution of these precassuslg FOFS scheduling alorthm. = eee aaa 5 Calculate wak tme, average wat time and tum around time, average tum eran not a within oe eee to the tail of queue Pi. If around time of each process also draw the Gantt Chart. jueue PO is empty, then process at the head of queue PI is assign a quantum of rial Tine milliseconds. It not compete itis pre-empted and is itis placed into queve a cao | P2. Processes are run only when queues PO and Pl are empty and these et i Processes in queue P2 are execute in FCFS basis. m2 4 - This scheduling algorithm gives highest privrily Wy any process with « CPU es 2 ; burst of 8 milliseconds or less. These types of process get the CPU, and finishes Ee = its CPU burst, and go off for next UO burst, Bs 4 : Once it is finished processes which are needed more than 8 but less than 24 Solution : js selected for execution. milliseconds are’ also get executes quickly. With lower priority than shorter Here, Arrival time of proceso PLia zeros it ss ruc, So timeffeepomes Fi8= OPED ag - Long processes go downwards to queue P2 and are executes in FCFS from Now start time of another process is calculat queues PO and PI. pe nase aceet ea me) of previous process “+ Pas Start time = (tart time + Burst time of eer =04 ‘i ove time) of previous process EYIEeac eee 6.5" Thread Scheduling P3's Start time = (Start ime + Bo 2 in een = (8+2)=10 P4’s Start timeCe Pisces [Arrival Time | Burst Time | Start Time PL 0 : o 5 1 3 4 PB 2 1 7 Pe a 2 8 BB 4 5 10 EE “ime is calculated by subtraction of start time and arrival time, Wait Time = (Start Time ~ Arrival Time) Finish time is calculated by addition of Start Time and burst time. Finish Time = (Start Time + Burst Time) ‘Tum around time is calculated by subtraction of finish time ~ arrival time ‘Tum Around Time = (Finish Time ~ Arrival Time) Now wait Fy cpoomy seems «s el Consider folowing set of procosses burst ime given in risesnds, ST 91 CPU Arial tine and Ista the execion of hse proces Using FOFS chad Cealeulate wal time, aerago wat tine an um around tn, avrg fu around time of each process also draw the Gantt Chart. a Process No | Arrival Time | Burst Time Pt o 2 Pa. 3 1 P3. 5 6 ‘Solution : ‘At arrival time ‘0’ PI is comes hence selec it and scheduled it for execution Gantt chart 0 2 Now at time ‘2” check what is next process is arrival at time 2’ but at time ‘2 no Process | Arrival | Buret | Start | Wait | Finish | Turn process is comes. So no other process comes at time ‘' so vait upto time 2 to 3, : ‘Time | Time | ‘Time |\Time | Time | Around because at time‘, Next process arrived. ic. at time ‘' P2 is errived hence select it ? Sweufiace 2 i ‘Time scheduled it. Hence upto time 2" and ‘it isile PL 0 4 0 0 4 Shown in Gantt chart Pe 1 3 4 3 6 > el > al P3 2 1 a 5 6 o ef e ets ® PA 3 2 8 5 10 1 a “ ‘Similarly at time ‘4? no other process wil comes hence upto time Sit i walt P5 4 5 wo | 6 15 un hence at time ‘5’ P3 comes, so select it and scheduled it Now draw the Gantt chart Process | Arrival | Burst | Completion | Turn Around | Wait See at arrive time ‘0’ which process comes. Hore PI comes hence select it ax! x ‘Time | Time | Time ‘Time "| Time | Goats tt 1 0 2 2 2 a | pil p2|ps| psi ps] . 2 3 1 4 1 a o 4 #7 8 0 A i 7 1 6 o ; Chart ©. Now, Tera, G77 moana completion time andi calaated fom Gant ‘Total Turn Arrival Time = (4+6+6+7+11)=34 Conlaticn "Tm Pi complta tie 2 2, i 4nd PY ‘Total Wait Time = (0+3+5+5+6)=19 ‘Turn Around Time = ‘Completion Time - Arrival Time Average Tur Arrival Time = 2*5+8*7*1) 26.95 Pie 9-053 poe 4-let Average Wait Time = 2*3+5*+5+9) 58 ms pa = 1-5-6awe Oo EES se-care exe cpu & quesccore) Steins EF cpantnp Sten WESC) —_6cn | ou | Wait Time = Tum Around Time = Burst Time s Exercise Here, Wait Time of ell processes are zero, P1=0, P2=0,P3=0 . 11 Consider following st of processes ie [No process is actually waiting for CPU, in fact CPU is waiting for process, a oeraesacon with length of CPU Arrival time and burst time given Hence, Average Wait Time = 0-ms Istrato the execution ofthese process using FCFS sched ng slot. Calta Average Turn Around Time = 9/3=3ms wait time, average wait time and tum around time, ‘tum aroune { 8 process also draw the Gantt Chart, a ele Trample 663: Gonder folowing eat of processes wih length of CPU Arival time amd 3) 2 burst time given in miliseconds. itustrate the execution of these process using FCFS scheduling algorithm, Process | Arrival | Burst | [Procew | Arival | Burst Cakeiate wait ime, average wait time and tum around time, average tum, Time _| Time “| time _| time around time of each process also draw the Gantt Chart = 5 7 a To ‘arrival Time | Burst Time a 1 5 = 2 be Pt 2 3 PB 2 6 Pr 3 | a B 4 ‘ PA 3 7 Ph o [2 PS 6 4 = ; 4 4 Ps 8 5 5 a a = 2 Process | Arrival | Burst Process | Arrival | Burst | Solution : ‘Time | ‘Time i Time | Time Here ‘P5' is at arrive at time ‘0’ hence select it and scheduled it. PL o 7 Pi 2 i zea easePaT GE Es RB 3 2 [Process | Arrival [Burst | Start [Finish [Wait | Turn Around Es o_| $ moleca ; | Time | Time | ‘Time _| Time | Time Time a o a 3 ji Pe PL 2 3 2 5 o P2 4 6 5 u 1 w Process | Arrival | Burst, P3 6 4 u 15 5 | time: | ‘Time P4 8 5 15 20 7 2 PL 0 0 PS o 2 o 2 o 2 P2 0 1 time . O21+547+0) PB a 2 Average Wait time = : 2.6 ms 7 5 5 B+ ‘Average Turn Around time = S+7+9+12+2) _ 6.6 m5 @) SOF: Examples c= [5 [pi | pm | ps | pa DON ive SUF scheduling jon-pre-emptive ; process comes for o 2 6 i 4% 2 5 snptive scheduling if any hiher ‘Remember that in non-pre-emptve seOk " until it not executing it will never sap until it nt Z 2 ie. it complete frst eurrently execution Poe 20 | 6-a a “ene CPU sent L280. e410 porting Sytem (MU8SC-Con) EE cowang rte 990g) 40 Ey sn of CPU Arrival time Example 6.6.4: Consider folowing sot of processes with length and Reavis eas Durst time given in miliseconds. is Beeson * | Start | Finish |) Wait | Tura ff Mlustrate the execution of these process using Non-pre-emptive Sjr ime | Time | Time | Time | Time | Around ‘scheduling aigorthm Calculate walt time, average walt time and tum ‘round time, average tum around tina of each process also draw the Gant Time i Pa 4 2 9 Chart nif 7 Process | Arrival | Burst F6. 2 8 16 4 u 9 | time | Time - Average WaitTine = ©222825010_ 5 PL 1 7 P2 2 5 Average Turn Around Time = 7*14$627+19) 46, Ps 3 1 7 Example 6.5.5: Consider folowing set of processes wih lngih ef GPU Arival ne and Pa 4 ; burst time given in miizeconds. PS 5 8 lustre the execution of these process using! Nonpro-emptve SIF | scheduling algorithm. Calculate wait time, average wat te and tum Solution : around time, average turnaround imo ofeach process also draw the Gant Here first we draw the Gantt chart start at ‘0’. Here at ‘zero’ no process is comes Chart. so check minimum arrival time. Process | Arrival | Burst Here arrival tim j Time | Time But at ‘0’ to ‘I’ CPU is Idle oft Pt 0 8 So at time'I’P, is comes hence select it and it, he pe [3 5 required execution time is ‘7. pa] 4 | 10 Now in SJF choose smallest burst time process. ps | 6 9 Here smallest Burst Time process is P3. aie 7 It this way select process for less burst time upto large es Haan? Burst Time. Upto P5 it is executed shown in Gantt chart + at time 1s hence select it and scheduled ey Here, at time‘0' process PI comes hen See ic Pa | Po | Pa |"p2 | PO tt ‘Once P1 is finished then check whose Burst time is less bere dat tg DB Rae aie time hence select it and scheduled it in this manner P2 is selected then P5, the PA an lastly P3, Process | Arrival | Burst | Start | Finish | “Wait |~ Turn ‘Time i Time i PI 1 8 7 L # P2 2 5 i 16 9 14 i Fa 3 8 9 5 6 is N iS o t aaConsider folowing set of processes with length of CPU Arval time and burst ime given PL oe. 1 oo i! » Te] t tf a 048) (+5) (1847) 2049) (29410) ——— - tt t Process | Arrival] Burst | Start | Finish, | Wal 5 arse /at er er er Time | Time | Time | time Tera Po PS PAO al 0 2 = ie ne oe on Pe, 1 1 2 | oa) ne = P3 2 1 a_[ 2 [oe 7 ‘Turn Around Time | ; ae (c= ‘Average Wait Time = St18+19. 19. > Average Turn Around Time = e820 0 ms 35 Exercise : = at 2 Average Turn Around Time = Average Wait Time = =9.2ms (8 +104 35 +23 +9) 5 (+5 + 2541442) 5 17 ms Example 6.6.6 : Solution : Consider following set of processes with length of CPU Arival time and burst time given in milliseconds, Mlustrate the execution of these process using Non-pre-emptive SIF ‘scheduling algorithm. Calculate wait time, average walt tme and tum around time, average tum around time of each process also craw the Gantt Chart. Burst Time Pt o 20 P2 1 1 3 2 1 Process, Here Arrival Time of process P1 is zero hence select it and scheduled it. e- [Pi om ‘Now select small burst time process Here, P2is selected » 3) inmillseconds. Mustrate the execution of these process using Non-pre-emplive SJF scheduling algorithm. Calculate wait time, average wait time and tum around time, average tum ‘around time of each process also draw the Gant Char. 2) Process | Arrival | Burst ‘Process [Arrival | Burst ‘Time |- Time Time _| Time PO 0 1 PO 0 1 PL 1 3 PL 0 2 P2 2 2 Pa a e PS 3 5 4 Burst Process | "Arrival | Burst ‘Prosess | Arrival Time_| Time aes ine Pl 0 1 mj 1 ts P2 ° 2 mi {| o 1 _* 7 PB 1 4 e 2 4 wm | 3 | 3 PA 2 7 ni 2 20182) Preemptive SUF scheduling examples ‘Remember that in pre-emptive scheduling if any higher priority process arrived {for execution then current process execution is stop it and that higher priority based ‘process executed first and then currently stopped process again start it’s execution Consider following set of processes with length of CPU Arrival time and burst time given in milliseconds. Iystrate the execution of these process using Pre-emptive SJF schedulng ‘algorithm. Calculate wait time, average walt time and tum around tine, average tum around time of each process also draw the Gantt Chart. Brommsoeneuesccmy og 2 process i arived hens . rence stop process Pl at time + Remaining Burst time of Pl = Burst Time ~¢ fim 1 7-126 ‘Time - Complete Burst Time Remaining Burst Time = 6 Now, Burst Time of Pl = and Burst Time of P2 = 5 Here, less Burst time is 5, Hence select P2 and executed it G PL Pa. Similarly process ou P2iis executed upto 2 because at time 2’ P3 is arrived, Ge PL P2 o 1 2 Now remaining Burst Time of P2 =5-1=4 Now Check remaining Burst Time of Pl, P2, PS Pl =6 P: Pa=3 jz ‘Here P3 has less burst time so select it and exeeuted it P3 is exacted again, PL po | Pa ° 1 2 Now,next process is Arrival at'3'is, PQ is execute upto one unit from 2 to 3. PL P2 ° + Remaining Burst Time of PS 1 Process | Arrival] Burst fs Time | Time PI o 7 P2 1 5 P3 2 3 P4 3 1 PS 4 2 Pé 5 1 Solution: Here process P1 is arrived at ‘0’ hence select it and executed it. » Ge [PL o But at arrival time ‘’ process P2 is comes hence from 0 to 1 only process P1# executed and stop. e= [Pr 01 Now, check again remaining burst time of process PL, P2, Pa Pl= P2 PS 6 4 2 Paz smallest burst time is lie. P4has Hes eat ime hence select it and scheduled it But at arrival time 3 process P4 is arrived “Select it and executed it. pi | P2 pa | Pt[BE cperng stom wu9sc-cong) __ #8 SPU Sheng (BF ceraing Systom (MU-BS0-Comp) ea zs Remaining Burst Time of Pd = 1-1=0 ee Here process P4 is executed completely because it's remaining burst time is PL Pra] Fa] Hi zero, So itis finished. Olea 4s I Now at arrival time ‘4’ PS process is arrived Now remaining burst time of process Pa = 11 et I Seale Here process P3 is exected compl i ; i Posi sl “! soit is Gnished. ctely because it’s remaining burst time is zero 0 6 P| P2} Ps | Pa Paps] | 1 4 O 123 466 | emaining Process | Burst Arsival t 4 2 2 | finishea 7 rst Aviva Tne | Tine Resin ast Poss f | 6 | y s 9 P2 1 i 4 4 2 Ps 2 5 - | 5 x = a o Fao’ il q P5 4 2 . ! i ‘Now amounts these process smallest burst Time is 2 but here P9 and PS has es 8 1 i i ‘same burst Time. Here select P3 for execution because of it's less arrival Time hence ‘Now select smallest Burst Time process which is P6 E t select it and scheduled it again. Pi] p2 [pa] ps] ps [Ps] Po : Pi | p2 | Pa] Pa | P3 NTI RSE | o1234 P6 is executed unit ‘’ that is i's Burst Time is ‘1’ hence. it required only one | Here again at Time 5’ P6 process is arrived hence P9 is executed only one unit, unit time. : Pi | p2 [ps | ps] es ‘ Pi [pa] Ps] Ps] Ps] pa] Pé f ; ca ane 4 6 OF i i Remaining Burst Time of process PG = 1 - 1 = 0 Here process PS is executed f completely because it’s remaining Burst Time is zero so itis ished. 4 ~— eoceas [Arrival Tine | Renaling Bors Tne | t Process | Arrival Time | z a 0 6 | E PL 0 a u P2 1 i Pa z 4 re 5 ° Finished i P3 2 1 Finished i a 2 Finished fi Pa 3 0 Finished a i 2 i PS 4 2 = 5 0 Finished PS 5 1 mf PS whose burst time is Now among 6 processes are remaining Pl and 7 ‘Again check smallest Burst time. Here, smallest Burst time process is P3 = 1 5° me eR voy i select it anc and execute it 's remaii i ise ee 5 ar id scheduled it and execute it upto it’s remaining burst time that is Now ents Buna Time is 2fr press 20 a=TT ne in stom (UBS &. qwu.ase. oo PU Senodul GBF operating Systom (MU-BSC-Co eo cru { | <1. Select it and scheduled it upto it’s remaining Burst Time ‘2 pi] p2] ps] ps [Ps [pa|P6|p5 [pa] pr i Pi p2[Ps|P4[ps] ps [Ps | ps 0123465 679 919 | 012345 67 + } Now remaining Burst Time executed completely (03 +6) | ale Process | Arrival Time | Remalaiang Burt Time PL 0 | o123465 679 es t ¢ | t | PB 2 0 { +2) Pa z nq ' ee PB 4 0 | Previous process unit Remaining Burst 3 5 a | Time unit Saas anise Sioa ‘Once all processes Burst Time is zero all processes are finished i's execution. PI a 5 Now caleulate wait Time, turn around Time. oss | Anal Tine| But Tine Twat Te] Tarn rie Tie (TA) Pz 1 4 cars Pa 2 0 Finished Pt a 7 2 a Pa 3 0 Finished 2 Hi 5 rn 7 2 5 4 0 Finished Pa 2 3 fe + 4 @ H Ps 5 0 Finished 3 3 4 ; 5 : Now process P2 and Pl is executed P2 has small Burst Time so select it and a A 1 7 : . scheduled it up to remaining Burst Time 4’ z ie 7eis0eSe) 4, j Pi|P2|Ps|pa|Pa|ps|P6]P5|P2 aaa a 4124441454 o12346 6791 Average tur around tine = 222+4#14522. 7165 | 5 ath | +4 sale 65.8; Corie eovng sl of pz wi rth of CPU Aral ie and i 7 ; = burst time given in miliseconds. i Process | Arrival Time | Remaining Burst Time iutato the executon of thoes proces using Preemve SUF sched } PL 0 6 algorithm. Calculate wat time, 20008 Oe the Gat Chart i Pe 7 a : ‘svorage tum around ime of each roeass { Finished Process [Arrival Time [Burst Time 2 ° Finished PI 3 4 j Pa 3 0 Finished Pe. 4 2 i PS 4 0 Finished PS 5 4 i 2. 5 o Finished Pa 2 @ | Now one remaini Pl i F inl PS areas remaining process Pl is selected and scheduled it upto remaining 6 2 asBF oper 950-Core) £50 SPU Scheie ‘Solution : Here, arrival time is not zero a + from 0 to 1 itis Idle oft Ie :, At at arrival Time ‘I’ P5 process comes hence itis selected and executed upty ‘next arrival Time ‘2’ Ps <: Ibis executed only one unit oF We 144 Remaining Burst Time of process P5 = 8- 1=7 Now at time ‘2’ process P4 and P6 are arrived at time ‘2’ and burst time of P4=6 and P6=4. But smallest burst time of process P6 is less hence select it and scheduled it and execute it upto next arrival Time. BET ps | pe Remaining burst time of process P6 = 4—1=3 ‘Now at arrival time 3" process P1 is comes But before that check smallest remaining burst time among above processes 5, P6 and PI. ‘Remaining Process | Burst Arrival Time | Remaining Burst Time PL 3 - 4 P2 4 2 BB 5 1 PA 2 6 PS. 1 7 PS 2 3 Now among process P5, P6 and Pl select process for execution whose remaining burst time is less. re [re P5=7,P6=3,P1=4 5 =i " Select P6 again Ide Remaining Burst Time of process P6 = 3-1=2 Now next at arrival time 4 P2 process is arrived in ready queue for executio?- ‘Remaining Burst Time. natant retin Syste (MU-BSC-Comp) 7 - ope H est coussesi Process | Arrival Timo | Remaining Burst Time PL 3 4 P2 4 2 Pa 5 i PA 2 fi P5 1 7 | P6 2 2 f Now among process P5, P6, P2 j Select process whose remaining Burst time less f P5=7,P6=2,P2=2 PG and P2 has same remaining burst time inthis situation check small arrival Arrival Time of P6 = 2, Arrival Time of P2 *, Select process P6 for execution and executed it upto next arrival time i.e. upto one unit only. Ps [re] re] Pe ot * -, Remaining Burst time of process P6=2-1=1 Now at arrival time ‘S process P3 is comes in ready queve. 5, P6 and P3 processes are available *. Remaining Burst time of process are P5=7, Pé=1, P8=1 ; —— Here, P6 and PS have same remaining Burst time. So check less arriv Process. . Here ‘Arrival time of P6 i les’ Tes selected for execution. Process | Arrival Time | Remaining Burst Time PL P2 P3 Pé PS 6BE operating syrom v.050-Cong) 2 hg P6is executed upto remaining burst time Unit ‘I’ P6=1-1=0 Here P6 is finished it's execution. Process | Arrival Time | Remaining Burst Time | -. PL 3 4 P2 4 2 P3 5 1 Pa 2 6 PS 1 7 Pe 2 0 finished Hs [Tr P6 ont . 3 Iie ‘Now améng process P6 is finished and now remaining process P65, P4, PI, P2, P3 Check who is having less burst time P5=7,P=6,Pl 24,P2=2, P)= :. Less burst time process P3 is selected and time. It has one‘ unit remained. if executed upto remaining burst Ps | Ps “itis executed upto one unit, Ps [ Ps | ps | Pa 7 finished ofafalefefa finished Now, select next process burst time is leas. 6, PA, Pl, P2 execution upto remaining burst time'2! =e 1 : : 3 ae T4H2 Rating tran 2 Process | Arrival Time | Burst Time PL 8 4 P2 4 0 | fated Pa o o[fniaes PA 2 é P5 1 7 P6 2 0 [tins Now PS, P4, PI processes are availabe in ready fr execution. Now select less Burst time process among P65, P4, Pl, P5 = 7, P4=6,Pl=4,P1 =4 =l=[=[e]*["["[A ° aL Ide ‘Process | Arrival Time | Remaining Burst Time |“ 3 @ finiched =f ss PS. 6 0 finished PA 2 : PS. 1 : Pe 2 o finished = i ‘pto its burst time 6. Now select Pa for execution and itis executed ete = Bl: re] re [ell mt 7% ot 2 ie as 2016_ syste MULESC-Cony Bh operating sea pening te uu BSC oss cpu i =6-6=0 : x. Remaining Burst Time P4 6 | sed tae i upto it’ ‘bs ow nex process PS is selected for execution and it executed upto its remy ‘burst time unit 7 : z ing Process, ‘Remaining Burst Time PL 3 0 finished P2 4 o finished Ps__|6 9 finished 2 o finished PB |t 7 ee e finished is remaining for execution in ready queve so it is executed. Pe | Ps | Pe 2 Pt] Pa] Ps 2 = 18 a a Pe ‘ 7 , : : pals 7 : ‘ m i ; £ ts 7 r : 8 a 8 3 Ps a : : : ‘Average wait time = Ssbe1sis 1640 =6.5 ms = 00+5 4241742544) Average turn around time = “0+5*2+17225+0 45 Exereise 2.1 Consider following set of processes with length of CPU Arival time and burst time in iliseconds. Iustrate the execution of these process using Pre-emative SJF scheduling algorithm. Calculate wait time, average wait time and turn around ime, average tum around time of each process also draw the Gantt Chart. » Arrival Time | Burst Time Burst Time i i » | Arrival Time | Burst Time Process: PL P2 PB. Process PL P2 Pa Pa Process PL P2 PS Pa PS: PS(U-BSC-Com) 658 py » Process | Arrival Time | Burst Time PL 1 7 2 2 3 P3 3 2 PA o 4 5 ‘Process | Arrival Time | Burst Time PO 1 2 PL ° 1 Pe 2 1 PB 2 6 P4 3 9 (9) Priority Scheduling Dv + Consider following set Durst time given in mili lsrate the exoout of processes with length of CPU Arival time at en length of CPU Arrival Hon these process using Non-pre-emptive pri! Scheduling algorithm. Calculate, wait time, averago walt tine a aaa ‘ime, average tum around time of each Process also draw the Gat Process | Arrivai Time | Burst Time Priority Pt ° 4 4 Pe 1 5 5 P3 2 1 71H) Pa 3 2 2 PS 4 3 1 P6 5 6 6 EB cpg te 85a) es PU Sepa Solution Here, higher priority is ‘7. Low digits indicates that, tis hicheet a that, itis highest priority and high digit indicates that, itis lowest priority, seid Some times in problem priority is assign to process Check at arrival time ‘0! who ‘Process will come here Pl is comes at arrival im’ Hence select it and scheduled it upto its given Burst time + Gantt chart'= - [pT] o4 ‘Now select second higher processes for upto arrival time 4 processes is comes for exo «Roady queue = Pl, P2, P3, P4, PS ‘But PS has higher Priority hence select it and scheduled it upto its given burst that check ready queue. In ready queue cation, time. Pil Ps ‘O48 Now at arrival time ‘S' process is added in ready queue, PI, P2, P3, P&.,P5, PS these are in ready queue, but Pl and P3 is finished +: In ready queue available processes are, P2, Pd, P5, P6. Now check next higher priority process which is P6 select and scheduled upto ven its burst time’. [3] o4 5 un Now next higher priority process is P2 hence select it and scheduled it upto Biven its burst time's? flein|e 04s ue Now next higher priority process is P4 hence select it and scheduled it for Sxecution upto given its burst time 2. pi | Po} P6| P2| Pa o4 5 1 18 Now next remaining proces is P. pe ela ; Select it and scheduled it for execution upto its given burs 20\8-we ws a SPU Set (rar [ro [m2 [Pe] Ps O45 uo 18 2 Frases [Aral Burst Tine | Completion Time | Wait Time | Tur Around Time a [| o | 4 4 9 4 ee 16 BS 18 we 2 | 5 2 3 a er ri 8 5 ei «| 3 2 m1 oils i 0 Fi rene wating » CHEE 55 avenge tamarnad tine « 2282221521720 5, onside following set of processes with length of GPU Arrival time and burst time given in miliseconds. Iystrate the execution of these process using Non-pre-emptive priory ‘scheduling algorithm. Calculate wait time, average wait time and tum erage turn around time of each process also draw the Gant ‘Arrival Time | Burst Time | Priority ° 2 3 Pi 1 fl 1 Pa, 2 2 2 Pa. 3 1 6 PS. 4 3 7Z Solution : Here priority is not assign hence consider low digit value 1 is higher priority which is P1, But at arrival time ‘0’ PO process comes hence select it and scheduled it and execute it upto given its burst time. +. Gantt chart = [Po Now at time ‘2 Pi and P2 process comes for execution but higher prioritY process is Pl hence select it and scheduled it and execute it upto given it's burst time. Bi omamgspenwssccny sso ried on a) Now at arrival time ‘S' P3 process comes for execution hence in ready queue available processes are P2, PS. But P2 has higher priority process hence select and scheduled it and execute ‘upto given burst time. ‘ Po] Pi [pa | oveaiiaras Now at arrival time ‘5’ Pa process comes for execution hence in ready queue available processes are P3 and P4. Here again P3 has higher priority process. Hence selec it and scheduled it and execute it upto its given burst time, Po] pi |P2| Pa 023 5 6 Now last remaining process is P& hence scheduled it and execute it upto given its burst time. i po] ri [Pepa [Pa 4 023 6 6 9 Process | Arrival | Burst | Completion | Wait Time | Turn Around Time Time | Time | Time _|@AT-BN| _ (CT-AT) PO o 2 2 9 2 PL 1 1 3 1 zi P2 2 2 5 7 £ PS 3 [4 6 a ; L_ Pa 4 3 2 2 @+1+141+9) Average Wait Time = 5 ims ‘Average Turn Around Time = 5 Sms i 44— (OS EES EET SE SNE e& (wu-880-Comp) oo CPU Scho [FF operating System MU-8SC-Comp) 1 « 2 ee © 0.1 Consider folowing set of processes wih length of CPU Arval time and burst time gen ocioy | ES in mitscconds. lp ‘time | Burst Time | Priority Tvate tho execution of these process using Non-pre-emptve rity schedig 1 1 7 gory, Calouate wat time, average wat time and tum arcund te, average tay PL 0 A ; fraud tne ofeach proces alto draw the Gantt Char. = 2 : : ° i ES e 9 1D [Process | Arrival Time | Burst Time | Priority = fi < 2 Po 1 3 1 ms ; x 2 m 2 a a ‘Note that here arrival time snot zerohence upto‘ itis lle P2 1 7 3a @ (2) Pre-emptive priority scheduling We know that pre-emptive scheduling means it any higher priority process Process | Arrival Time | Burst Time | Priority Po 0 2 3 comes for execution then current process stop its execution and start higher Pi 2 Sj aan Priority posesses execution ose higher pony promss finished, then stoped processes again starts its execution P2 1 3 7 EE = a a r Example 6.6.11: Consider following set of processes with length of CPU Artal time and burst ime given in milseconds ® Ilustrate the execution of these process using pre-emptive prioty ‘scheduling algoriti. Calculate wait tme, average wait time and tum Process | Arrival time | Burst Time | Priority rago tum around tine of each process also draw the Gantt ~ : 7 ‘Artval te | Burst Time | Priority | PL 2 3 2 a 7 a P2 ° 5 a P2 2 2 5 P3 1 4 4 Pa 2 3 + w PA 3 s_| etn ‘Process | Arrival Time | Burst Time | Priority PS 3 4 . PO 2 1 1 P6 4 2 s =i 7 7 7 Here arrival time is not ‘hence upto ne P3 1 1 9) PA 4 5 4 2016aa remaining burst time 2’. gee Booman ye ee a nts Sioa Now P6 has higher remaining Burst time, PB operating son iu 880.) 582 SPU Seta Now at arrival time P1 comes and it is Pt executed next arrival time that is only one ‘unit. de + Remaining burst time of process Pl = 4—1= 3 ‘Now at time 2’ two processes are arrived that is P2 and #3 : P2- Arrival Time = 2 and P3. Arrival Time = 2 In this priority scheduling we check whose's process priority is high. Here p thas high priority hence select it and scheduled it upto next arrival time = 3, Soit execute only one unit. Pi | Pa Oh} anes Remaining Burst Time of P3 = 3-1=2 ‘Now upto arrival time ‘' Pé and P5 processes are available in ready queue. But here P4 has higher priority. Hence select it and schedi Because Burst time is ‘6’ due to higher time 5, luled it upto it’s given burst time, Priority process it is executed upto give burst Pi [ps | Pa om1 2 3 8 Tale +: Pais finished, Arrival time | Burst Time | Priority Finished (since 1 + has higher Priority so it is finished first ) a falas |= if [es feo fae [ro fee wo [H Jo |e |r fe @ fo fal|s fora Now second higher priority is P9, is 7 hence select it and scheduled it upl? Pt | p3| Ps] P3 Caan Here, P3 is finished. Now remaining processes are P1, P2, P5, P6, 8s hence check whose process is arri e's Arrival time = 2 P5's Arrival time = 3, mer eS time 2’, remaining burst time ‘I. remaining burst time. Prosess hence select it and executed it upto ES O12 a5 ya Here, POs finished now remaining processes are Pl, P2and PS, P2 and PS has same priority proce it’s Here, P2 is arrived first hence scheduled it ‘and execute it upto remaining Burst Pi | p3| pa [Ps | P6| pe oTl 203 8 1 12 4 Idle i Here, P2 is finished. ' Now remaining high priority process is P5, Hence select ifand scheduled it upto Pi} P3| pa] Ps |p| pe [ps ofl 2 3 8 0 2 4 15 Idle 6 is finished. Now remaining priority processes is Pl hence scheduled it upto pi | ps] pa | ps|P6[P2| Ps [ pr O11 2 3 8 0 2 14 15 18 Process | Priority | Arrival] Burst | Completion | Wait | Turn Time | Time| Time | Time| Around ¢i Time PL 1 1 4 18 13 1 Pm 2 sulla «| | 2 a ; 2 les 10 cela PA 4 3_| 5 G o_j_s pfs [os [rf w [ul 2 P6 6 4 [2 2 nts 2016(Zh operating sym mussc-cong) 864 OP Sng og _ (941045404146) Average Wait Time = 3 = 75 ms (174124+8+5+12+8) 6 Average Turn Around Time = = 10.33 ms a _ ‘Example 6.6.12 + Consider following set of processes with length of CPU Arrival time and burst ime given in milliseconds. | Nustrate the execution of these process using pre-emptive priority scheduling algorithm. Calculate walt time, average wait time and tum ‘around time, average tum around time of each process also draw the Gantt Chart Process | Arrival Time | Burst Time | Priority PI 1 5 P2 P3 Pa PS P6 lo |~ [> fo {ro Solution : Here high priority process is P6 which has 8 and low priority process is P2. But at arrival time ‘0' P4 process comes hence select it and scheduled it upto next arrival time thatis only one unit. + Gantt chart = | P4 oa Here P4 required only one unit which is given as process PA has Burst time ‘l hence itis finished. Now at arrival time ‘1’ Pi. process comes hence select it and scheduled it upto next arrival time thatis only one unit. [ri] o 1.2 + Remaining burst time of Pl=4-1=3 Now at arrival time ‘2’ P2 process comes hence select it and scheduled it upto next arrival time that is only one unit so among P1, P2, P1 has higher priority proces* hence select it and execute it upto one unit . 4 [pi] pi o12 3 By operaing Sym MUSC-Cong) 6s CPU Schedul Now remaining burst time of Pl =3-1=2 Now at arrival time ‘3! P3 process comes hence select it and scheduled it upto next arrival time that is only one unit P4| pi | pi| pa o 1234 ‘Now among processes in ready queue Pl, P2, P3 processes are availabe, but P3 has higher priority hence select it and execute upto next arrival time, p4|pi| piles o12 34 ‘Now remaining burst time of P3 = 6-1=5 Now at arrival time ‘d’ P5 process comes for execution an it executed only one unit. pé[pi[pi| Pa] Ps oll 2 3 4°5 :. Remaining burst time of P ‘Remaining burst time Process | Arrival Time | Remaining Burst Time! Priority PL 21 2 - Pa. 2 e 2 PS. 3 . ‘ Be 0 O-fnished 7 PS 4 4 P6 5 e 2 xa Pais Sins and now at arial time ‘PO proces Now among above p sjanee select it and acheduled it upto its is comes and it has very high priority proces burst time that is ‘3’ unit a all o127 9466 P6 is finished ate Now next higher priority process og burst time that is one unit Hence select it and ee 5 iinet) 20 6-48 E 1we — ori aS [EF operating Syston (uv-856-Core) 666. Us. [FF operating System (MU-BSC-Con) et van PS is finished. a Now remaining burst time ee ‘Process | Arrival Time | Burst Time | Priori ial = Average Turn Around Time = 05+19+11+145%3) PL 1 2 5 $ =9ms P2 2 5 2 Exercise j P3 3 5 6 Q.1, Consider following et of processes wih ength et CPU Ava ne and burs time gion ' Pa 0 0 4 in mlisoconds. 9 oa 7 a a Iusirate the execution of tese process using pre-emptive prt scheduling algo, : Calculate wait time, average wait time and tum around tie, average tum aroced te P6 . GB of each process also draw the Gantt Chart Now remaining processes are P1, P2, P3. w igh. priorit has high priori last i PS has high priority then P1 has high priority and lastly remaining P2 are ja executes in given manner. er 1 ume : f + P3 is select and executed upto it’s remaining burst tim = 5 ; 5 i pa[p1 [Pi] ps] Ps | Pe] ps] Ps 5 5 fc 3 0128 45 89 PA 4 3 am PS is Ginished. P5 5 6 8 . Now select Pi and execute it upto its remaining Burst time ‘2’. oo Pa| Pe | Pi | P3| P5 | P6| P5|P3 | PL Process | Arrival Time | Burst Time | Priority Of itey 2s) e aos aie oe 1416) Pil 0 1) Plis finished. 5 1 2 Now last remaining process is P2 executed upto its remaining burst time ‘5 es 2 2 3 it 4 unit, PA 3 3 : 4[pi| pi] ps| Ps] Pe [Ps | Ps [pi [pa rE 4 4 O.1 2 34 5 8 9 4 16 a ® [eaval Tine | Burst Time aa Wait | Turn Around Time PL 1 £ 3 3 “| Time i P2 2 : Fi PI 1 4 16 1 15 PB 0 5 a P2 2 5 21 14 19 Pa e aa 10 3 3 6 4 6 rr PS 2 s 2 Pa 0 1 L 0 1 P6 o PS 4 2 9 3 5 Pe 5 3 8 ° a 20|8-4o ‘Process PL 0 9 P2 2 PS. 2 3 9 ‘Process | Arrival Time | Burst Time | Priority PL 1 fi 10 P2 2 6 9 P3 0 4 23 PA 9 3 20 PS 7 5 15 (@)_AR-Round Robin Example 6.6.19 : Consider following set of processes with length of CPU Amival time and Solution : burst time given in milliseconds. Ilystrate the execution of these process using Round Robin scheduling algorithm. Calculate wait time, average wait time and tum around tine, average tum around time of each process also draw the Gantt Chart Ta=2 Process | Arrival Time | Burst Time PI o 4 Pe PS. Pa PS PS In this scheduling time quantum is give ‘2’ unit. Itis pre-emptive icheduling. In BR we monition ready queue. Ready queues has order of process. G= a enna ‘operating Systom (MU-BSC-Comp) CPU Seneduing At arrival 0’ process P1 is comes, -. Ready queue G ey 02 Hore, 2 is given time quantum or time slice, ‘Remember that in RR every proces is executed upto given time quantum. [Now at arrival time 2" check which processes are comes ie, Add proestes in ready queue upto arrival time 2 z. Ready queue = Pl, P2, P3 Now Remaining Burst time of PL = Burst Time~ Time Quantum = 4~ Here, remaining Burst time of process Pl is‘! hence again‘ is added in ready queue as =2 Ready queue = P1,(@D); P3 .PL [Now select next process from ready queue and execute it upto time quentim 2 pi [Pa 024 eck which processes are comes that is add process is Now at arrival time ‘che ready queue upto arrival time’. Ready queue = Pl, P2, P3, Pl, P4, P6 Now Remaining Burst time of P2= Burst Time Time quantum = 4 =2= 2 Here, remaining Barat time of process P2 is‘ hence again itis ded in ready ene Ready queue = P1, P2, Now select next process fro PI, P4,P5,P2 ready queue and execute upto time ont 8 check: which processes are cet quantum 2 that is add process in Now at arrival time ‘6 ready queue upto arrival time Here upto arrival time“ Processes P6 which is added in’ ready queue 2, P3, PI, 4 PB ‘added in queue so caly remaining all processes aT& Here remaining Burst ‘tdded in ready queue agein 9 |670 CPU Sched PET operating System (MU-BSC-Comp) en CPU Scheing t ‘Burst Tim Ready queue | Arrival Time e 71.72 @QB.Bs,02.8 | 0 2 j 1 3 Fishes 2 0 finished ‘ i a 5 7 Now select PS upto given time quantum 2, : P5 4 6 (eTe [Te To pepe i Ps 5 3 ° i ; Ready queue = Pl, P2, GRYP1, PA, PS, P2, PS ‘ny oe unt ia i i t finished Now remaining Burst time of PS = Burst Time - Time Quantum Now select next process Pl upto time quantum'2’ [1 | 2 | 3 | Pr ua ae eS rt } anos this proces in alien ry duo | ready Queue =P1, 2, (28), BRL Co, DOC PP, . zero which means it is finished so n¢ oe ‘Now select next process for execution form ready queue, P2 is selected and it is ae executed upto time quantum 2. ae : Pi] pe] a [pi [p4[P5]P2 0 _| Finishea 024689 NB 5 ae Remaining burst time of process P2=3-2=1 ia Hence again it is added in ready queve. 1 Randy queues PIP, Lest, ey OY, Pe, Po, PPA a Remaining burst time 3 “Process | Arrival Time | Remaining Burst Time | Ready queue -P1, P2, (BAY DPR, Ps, P5, PZ, P6 Pi : a id Pe 1 : finished finished ref 2 2 eased Now select next process from ready queue PA is selected and it is executed upto Pa 3 . sven time quantum but itis required only one Burst time which is given therefore it 5 A 4 iwexoouted only oneunit [re Pos [mr [oe 7 3 . 3 | 76 Tay ques elo for eatin po ren ime | _.__ Here again PA is required only one unit, which is already executed soitfinisbe NOW next proces PG [om it’s exertion hence remove from ready queue. Ss 1 P2, DRGPS, P2 Ready queve » PL, P2081 | Re eres ace = bow ™& on (MU-8S6-Com) sr CPU Sete Pi | p2|P3 [pi] P4] Ps | p2| Ps | o24689 1 1 Remaining burst time of P6 = 3-2=1 Here again P6 added in ready queue becouse it is remaining burst time is: Ready queve = P1, P2, 681 Bal PEL Ps, P2, re, Px, P2, Pe [pa [2 [ps [1 [ps | ps [p2 [Ps | ps 024 68 9 1 13 i%a7 -. Reaming burst time of P5 = 4~2=2 Here again PS is addod in ready a queue because it remaining burst time is2, Ready queue = Pt, P2, P5, P2, PB, PS, BA P6, P5 pi[p2|Ps [Pi |pa| ps [p2[ ps | Ps | P2 024 6.8 9 1.13 15 W718 t only one unit remaining burst time is required Here P2 is finished so no need to added in ready queue again Ready queue= Pi, P2, (ay, Pay Gay rs, Bel po, Ps, I< Ps, Ps Process | Arrival Time | Remaining Burst Time PI ° ° Finished P2 1 0 P3 2 ° Finished Pa 3 ° Finished PS. 4 2 PG 5 1 Now next process is P6 is selected it required only one unit hence it execute wp? one unit. pi [2] Ps |P1|P4|Ps|p2|P6|Ps|p2|P6 o24689 1B BMI 9 6s finished so no need to add again in ready queue Ready queue =P, P2, GRY, GRY Gel ps, el px verre, Be 5 BF operating sysom wuss. = PU Seto Now next process PS is selected from ready que eee dy queue and it executed upto given Ready queue _=_P1.P2, C8 G3L, SRY, ps {6Y, pers, po 7a Ps Pi | p2| p3| pr | ps] Ps [pe] p6 [Ps | Po | Pe] ps 024 689 ub wb aie a PS is finished here. Ready Queue = P1, P2, Pay LEST LORY, Ps, BY, Ps, ps, po, Po RT. Burst Process | Arrival Chaput Tas WEE Time | Time rae oa cao PL o [4 5 a 3 Pe 1 [5 8 a 7 PS 2 [2 6 = P4 amma 9 a P5 ae 2 a 7 P6 5 13 18 it 4 eis 2+5 +1) Average Wait Time = 7 =1.5 ms _ (8474446417414) ‘Average Tum Around Time: = =11ms Example G14 Conair flowing et of peso wh er of CPU Ara ne ere burst time given in miliseconds. Pee en as rg Rn a ay Aiuann. Caleuate wat io, average wa tin and tum around Ee esrage tum around tne ot each pezess leo draw the ‘Process | Arrival Time | Burst Time Pt 5 5 Pe 4 6 PS: 3 z Pa 1 9 PS 2 | 2 1 3 Toe sd ina recess comes for execution s9 here at arial Here, at arrival time ‘0 ‘no other Pr time“1” process Pé comes. i |2 EEE eS a1. 560-C0 eal CPU Seheai [EFT operating System (MU-BSC-comg) 275 cry Now select Next process P3 and executed i <. From 0 to Lit is Idle een anne = Pe { o1 ope ae ‘ 138 as «: Remaining Burst Time of P3 is 7 oe = Hee remaining burst time of process PB is 4 hence again itis added in ready | nae ov. yweue for execution } And at arrival time ‘1’ P4 comes t Gey Oo, tT 4 iS . Ready Queue = ' hence select it and scheduled it upto given le EP oo it Ready Queue = P4, P5, PDE Ps, 1, P6, P3 i time quantum 8 ‘Now select a Process P2 for execution upto given time quantum before that 4 ‘Now at upto arrival time ‘’ check how many processes are arrived hence upto‘) ee | arrival time. Process | Arrival Time | Remaining Burst Time 5, P3, P2 processes are comes in ready queue for execution. Pi 5 5 «+ Ready queue = M4, P5, P3, P2 P2 4 6 ‘Now remaining burst time of process P4 is 9-3 = 6 P3 3 4 Here remaining burst time of processes P6 is ‘6’ hence again itis added in ready P4 1 6 queue for execution — 5 ji fuer + Ready Queue = P4, \b4) , P3, P2, P4 ' P6 6 3 Now select next process is P5 select it and executed it upto given time quantum Slee Te ‘3’ but it required only ‘2’ unit that is burst time of process P5 is ‘2’ hence it is o 1 6 8 8 2 4 executed only 2 unit cu «. Remaining Burst Time. of process P2is6-8=3 : £ Here remaining burst time process P2 ic 9 hence ngsin itis eded in ready 8 ‘queue for execution a | Ready Queue = P4, P5, P3, (py 2.25, ¥ j 4a2 ; o | ion time quantum | 1 Now select next process Pé for exezution upto Bive8 Burst ime of process PS o- fal pa] Ps] Ps | Pe at eae Now here PS is finished because remaining burst time of P5 = 0 aa foc Now at arrival time ‘6’ check how many processes are arrived in ready queue fot Now remaining burst tine ores PAO iin aed in edly execution. Here remaining burst time of pros z- Ready Queue = P4, P5, P3, P2, Pa weve for execution. 4, P6,P3, PRP ‘Now add upto ‘6’ arrival time processes that is Pl and P6 : Ready Queue = P4, P5, PS, P2s Phy 71 + In ready queue = P4, P5, PY, P2, P4, Pl, PSiS fo} o G ex i oO fos N fo} oO ° wwoce: Zs CU soe tion upto given is time quantum oR Bh cores en seer) ecru set ‘Now remaining time of process P2ie3-3=0 Now ale next procentP6 for execution upto given its ime quantum ere remaining burst time it 33 =0 Itie finished sono need to ad in ready queue «Ready Queue = P4, P5,P3,P2,P4, PL (pg, KI, P2, PA, PL [Now select next process PS from ready queue and execute it upto tine quantum 5 Gers «. Remaining Buret Time of process PS =4~8=1 Here remaining burst time of process ie ‘” hence again it is added into rouly queue fr execution Ready Queue = P4,P5, 2, P2, 4 P1, PO,PS, PS, P,P Now select next process P2 for execution from queue and itis executed five time quantum Tala Tata 7] me oot ex pric PLr 88 —s Itisfinished s0:n0 need to add again in realy queue oer Teele) apaning Bar Tine of poser oe ok ‘Process | Arrival Tine | Remaining Bunt Time ‘ow Renaising bast ine of roses PL = ns . : aan anineime hat tne of rece P #2 bence agin ii added in ready = 7 _queve for execution. . o finished wendy Que = PPS PB, F2,P6 PL PG FS P2, PPL P5 3 i Now agua we dk ll enanig burs ie ofl process Pe 1 a rac Arrival Time | Remaining Burst Time | 5 2 ° ted | 5 2 | Ps é a Site 3 + 4 Ready Queve = PPS, P2,P2,P4,P1,P6,P8 OR He PLP n | a ‘ow sl next procanP fr execation wo gine gut PS. 2 ° Finished Ge ele eee ee) refs 3 | Be ee | Retain Dine = 3-990 tet son edad rey qo ei | Nowecac nen pn rene os al a Tip QunceeP4Ps PPE D4 PPP P2 PKK PD | [Next proces Pl is selected for exzetin and executed it upto remaining burst | a (Wes [rs[ro[re[reTrs [re] Po] role] et On 4 © ojva8 18 4p_a1 4 90:08) lis finished oo no nec to ain ray queut Ready Queue = Pi, P5,P3,P2, Py Pl, P,P, P2, Ps Pu aa aan rec Pr ection anit a xed orang tent tine a sleds tries BM TO Re Tale_ re | a a mn Process | Arivat Time | Burat Time. | Completion Time | Walt Time | Tur Around Time » Pr 5 5 2 z 2 Piacoe | ANWR Pa 4 6 2 7 23 i — z P2 3 7 2 2 2 a 3 Tce qunumes Pa 1 @ 20 20 29 ra 7 3 6 2 4 Ps 2 2 5 6 6 3 21 2 5 , bbe 17+ 23 42042412 Process | Arrival Time | Burt Time ‘Average wait time = 2+17+2322042212 16 ms v i Average turn around tim (Hs25+30-+29+4+5) =21.3 ms Ee 4 2 P3 3 4 | Time Quantum =3 Exercise a 2 ‘ 0.1 Consider following set of processes with length of CPU Ava ime and burt time given PS T 3 in miliseconds. ~ = a Mustrate the execution of these process using Round Robin scheduling algoritim. Calelte wait time, average wal time and turnaround time, average tun around tne ‘ofeach process also draw the Gantt Chat. 0.1 Whatis mean by CPU Scheduling? 0.2 Explain the scheduling crteia. » . aa il time, ‘Tumaround time, PL 0 7 ‘Time Quantum = 1 as eee tllzation, Load average, Response time, Throughput, , ml Z 3 0.4 Explain FCFS CPU Scheduling wih exampe. P3 2 1 | Q.5_ Explain SUF CPU Scheduling with example. 2 ea Explain RR CPU Scheduling eam 7 ! Pep tine Tm scale renseretetts Pl 0 4 ‘Time Quantum =2 | 8 Explain Pre-emptive SJF scheduling algoritim with ‘example. bd Z 8 ©.10 Explain Pre-emptive scheduling algorthm. Fs: 2 7 11 Explain Non Pre-emptive scheduling algortim. P ©. 12 Explain Muttlevel Queue Scheduling. ; 3 4 2.12 Explain Mutlevel Feedback Queues Sched 7 Om read Scheduling. te satiate Arrival time and burst time given 1 CPU ©.15 Consider fotowing set of processes wih oro PL 1 4 Tim =4 in millisecond: sched algorithm .Calculate wait > Gast Itusrate tre execusn of thes proves using FA schediied AT foe oes } ra a 2 time, ae swat time and tum ‘around time, average { P3 o 7 also draw toe Gantt Chart. Consider Te quantum = t Pa 3 1le or rating System (MU-BSC-Comy | wssc-cons) 622 i Bcoeotra eL___ ses crvenwsiil | Burst ime 19 Consider following set of processes with length | ries aeees oN qmilisoconds ath of CPU Ava time and burs time given Pt o IMustrate the execution of these process usi ea fi a process also draw the Gantt Chart Considor v7 “ound time of each | Process | Arrival tim | 2.16 Consider follwing st of processes with length of CPU Arival time and burst time given S| Borat tie in millseconss, Mstralo the execution of these process using SJF pre-emptive im ' : | scheduling aigorthm. Calulato wat tme, average walt time and tum around time, P2 ° @ ! ‘average tum around time of each process also draw the Gantt Chart. Consider P3 0 7 | Process | Arrival time | Burst time 7 a A | [0 a a . i Pe 1 13 (0.20 Consider following set of processes with length of CPU Arial time and burs ime given Pa 2 5 in miliseconds Fa a a IMustrate the execution ofthese proces using Prot pre-emptive scheduling algorthm. | Calculate wait time, average wait imo and tum around time, average tur around time | Bs a 4 ‘of each process also draw the Gantt Char. {2.17 Consider following sat of processes with length of CPU Arrival timo and burst time given Consider in miliseconds,ilusrate the execution of these process using SJF non pre-emptive Process | Arrival ime | Burat time | Ponty ‘scheduling algorithm. Calculate wait time, average wait time and tum around time, 9 ant 7 average tum around tine of each process also draw the Gantt Chart Consider e fs a Process | Arrival time | Burst time e 2 L.brecese | Arrival time: Bur PS 2 5 5 a a e PA 3 ne 5 . PS 4 a [a 1 12 ve ° Pa a 5 2.21 Consider following set of processes with length of CPU Arival time and burst ime given in miliseconds A PS 3 6 Musas te exccutn of hee procs ning preemevePttyetedung am, 18 Consiroowng sto processes wth gt of CPU Arival imo and burs time ger asst wal tino, av0ge Wet Cort in millseconds lustate the execution of these process using FCFS scheduling at each process alsa ran Gat Caf Coit —— algorithm. Calelate wait time, average wait time and tum around time, average tum Process | Arrival time | Burst ‘around time of each process also draw the Gantt Chart PI 1 4} 1) ‘Consider | a 7 a 2 Process | Arrival time | Burst time a a 6 3 Pt 0 1 Ph 6 a < P3 2 3 Pa 3 4 PS 4 5aa BEF operating system nnu-256-Core) sz CPU Sched £0.22 Consider folowing sat of processes with length of CPU Arval time and burst time given inmiliseconds : ustrate tho execution of these process using non-pre-emplive Priority scheduing "assulate wat Sime, average wait time and tum around time, average tum ‘round tine ofeach process also draw the Gantt Chart. Consider ‘Process | Arrival time | Burst time | Priority Pi 5 6 1H) P2 a 9 2 PS. 9 4 3 Pa oO 1 4 PS. 1 1 5 2.28 Consider folowing set of processes with length of CPU Arrival time and burst time given inmiliseconds HMustate the execution of these process using non-pre-emptive Priority scheduling algorthm. Calculate wait tie, average wat timo and tum around time, average tum around tine ofeach process also draw the Gantt Chart Consider Process | Arrival time | Burst time | Priority Pi 1 11 1H) Pa o 5 2 Pa Zz 8 3 Pa 4 8 4 Ps. 3 5 gga Deadlocks University Prescribed Syllabus. ‘system Model, Deadlock Characterization, Methods for Handing Deadlocks, Deadlock Prevenion, Deadlock Avoidance, Deadock Detection, Recovery rom Deadiock. Introduction = Deadlock refers to a specific condition when two or more processes are each waiting for each another to release a resource, or more than two processes are waiting for resources in a circular chain A set of blocked processes each holding a resource and waiting to acquire resource held by another process in the set. = Ina computer system deadlocks arise when members of group of processes, which hold resources are blocked indefinitely from access to resources held by other processes within the group. Example = Pyrequests one /O controller and the aystem allocates one, = Pyrequests one /O controller and again the system allocates one. ~ Py wants another VO controller but has to wait since the system ran out of UO controllers. > Pi wants another /O controller: and waits. ~ Traffic only in one direction. > — Seetion of a bridge can be view as a resource: ~ Deadlock ean be resolved if one car backs uP- Several cars may have to be backed wp f= deadlock occurs. Starvation is possible.= The condition for deadlock in i : of acycle. ‘system using the AND condition is the existence - The condition for deadlock in a s fie Pee ‘ system using the OR condition is the existence of - Aknot (K) consists of a set of nodes such that for ever every node a in K and only the nodes in K are reachable from node sina @ @ ee» oe» ew | Fig 712 [7.1.3 Resource Allocations Proceed Like this 7.1 The Cause of Deadlock Request a resource (suspend until available ifmecessary). See. = . Use the resource, ES What are the causes of Deadlock ? ~ Release the resource. Each process needing what another process has. This results from sharitg Teas q Tesources such as memory, devices, links. Sr ‘Two types of deadlock [72 system Modet dic wei ing a resource and waiting to acquire a 1, Resource deadlock : Uses AND condition. A set of blocked processes ea _ a esource held by another process in AND condition : A process that requires resources for execution can proce! patie when it has acquired all those resources. ‘Sample of « dendiock probe ing, both shall come to a full ther at a crossing, both sl 2 Communication deadlock : Uses OR condition. ~ When two trains approach each oe one OR condition : A process that requires resources for execution can proceed stop and neither shall start uP Af es dstribted among number of when it has acquired at least one of those resources. ~ A system consist of finite number of reeour Peout-of-Q condition which means that a process simultaneously request® @ competing processes. ross uid eve device by setting status to every resources and remains blocked until it is granted any P of those resources: ~ Operating system keep ee and BUSY. AND-OR model, which may specify any combination of AND and OR models. device. Status of devices - to some process. Example : a AND (b OR o). BUSY means they are allocatedBenenson wssocmn) 74 _ ~ FREE means they are not allocated to any process. = Ithas three types of resources : 1. Shared resources means, they can share in between many resources 2 Dedicated resources means, at a time they can be allocated to ogg process. 3. Hybrid resources means, combination of above both resources, = If any process needs any input out operation then process send REQUEST signal to the resources, if resource is not allocated immediately then requesting process required to wait tll it can acquire the required resource, = When resources is allocated to process then status of resource is BUSY, ~ When process is finished operating system de-allocates all allocated resources from that process this is known as RELEASE. SIR ee eee 7.3 Deadlock Characterization E@_ Explain deadiock characterization, Following are the deadlock characterization 1. Mutual exclusion 2. Hold and war 3. No Preemption 4. Circular Wait 1. Mutual exclusion Write note on mutual exclusion. u opening stim sascceny 7g 2, Hold and Walt FF _ Write note on Hold and Wait. ~ _ Approcess holds a resource while waiting for another resource. ~ Process hold some resources and waiting for some other resources is Gangerous for system due to this deadlock is increased. If process are not ‘in waiting state then process will not going into BLOCK state so deadlock is not occurred. Stat Free Printer Pence [Rese ‘oe Stter= Fee New Sana Free Seamer ‘Sata = Fee 3. No-Preemption One or more than one resource must be held by a process in @ non-sharable (exclusive) mode. All resources are used in non shared mode. If all resources are used in shared mode then there is no chance of any deadlock condition because these resources are simultaneously allocated to many processes. ~ Some time we require to use some dedicated devices into shared mode, known as hybrid devices but in all situation, We could not use hybrid device because of overall efficiency of the system. ~ If we are using dedicated devices then every process required very les? time to execute so itis required to use some device in exclusive manner- ~ If any process send request to shared device then operating syste™ immediately allocate requested device to requesting process. ~ And in dedicated device only allocated to one process at a time if itis fe Ifstatus of these device are BUSY then it eannot be allocated. Write note on: No-Preemption Th =n ‘There is only wluntery relat of rerre no one elt ca pais ee! ‘When any process starts its execution it ‘thould se btnoo tha means ere tat procs i ot process give up a reso re ar ‘Status = Busy At a => ® Pt 2) ‘Status = Run ‘Suna = ase o ease Ba 7 aiSdie0 re suave iS 4 A) 8) wu-85C-Comg) 76. a bly this perating f any process fo Operating system could not stops the execution of any for is known as no pre-emption situation because of this policy of. system the chances of occurrence of deadlock increased. Cireutar Walt SF | Write note on : Circular Walt, = Process A waits for Process B, Process B waits for Process C, Process C waits for Process A. ‘When there is circular wait is Rt Present in system then there is deadlock occurred. If any process hold some resource and wait for (NESS ee SERIE (BF operating Systom (MU-BSC-Comp) z SEER Se Cats 7.4__Methods for Handling Deadlocks 55 _ Explain methods for handling deadlock, Prevention 3._Detection 2 Aveldance 4. Recovery Syllabus Topic : Deadlocks Pr 744, Deadlock Prevention EF _ Write note on deadiock prevention. some other resource which is holding by some other process and some other process also wait for resource which is hold by first process then there is deadlock occurred. Walt tor graph = Nodes correspond to processes (only). ‘There is an edge from process Pl to process P2 if P {for P2 to release some resource, wma © Set of processes P = (Pi, Pa ..P,) Set of resources P = (Rt, Re, ...Re) For every reusable resource R, negative i ource Ri, a no integer ti, the tot number of units present in the system - c= stem or every consumable resource Ri, a nonempty set of producers of Ri come ot Waltfor graph and Resouree-ellocation graph a meee = Graph with a single copy of resources can be transferred - Fig.7.33 Lis blocked waiting ° Prevent any one of the 4 conditions from happening. Prevention is generally the easiest to implement. 1, Mutual exelusion ~ In that all recourses are used in dedicated mode. ~ fall resource used in shared made then there is no chance to deadlock because of simultaneously slocated resourees to many proces. ~ Using spooling algorithm operating system converts dedicated resources to shared mode. — If there is no dedicated device there is no chanee of deadlock a all ~ Tautomatically hold for printers and other non-sharable ~ Shared entities (read only files) don’t need mutual exclusion (and aren't suscoptble to deadlock) ~ Prevention not possible since some devices are intrinsically non-sharable. Hold and wait (2) Collect all resources before execution / (b) Particular resource can only be requested when no others are being held. ‘A sequence of resources is always collected beginning with the same one, jon possible. (© Utilization i low, starvation poss ifall devices are current! Find out how any revres re rege to proses ial evi y free or available then allocate them to request process provessm (MU-BSC-Comg) 78 Deas No preemption When process starts its execution it should not stop its execution in between that means before that process is not over. 8) Release any resource already being held if the process can't got ep additional resource. b) Allow preemption - If a needed resource is held by another process, whith is also waiting on some resource, steal it. Otherwise wait. 4. Circular wait ‘When circular wait is present then there is deadlock occurred. Number resources and only request in ascending order. EACH of these prevention techniques may cause a decrease in utilization and/or resources. For this reason, prevention isn't necessarily the best technique. SELES eee een 7.4.2 Deadlock Avoidance EF_ Write note on deadlock avoidance. z Deadlock Avoidance : Allow all deadlock conditions, but calculate cycles about to happen and stop dangerous operations. If we have to know how resources will be requested, it's possible to determine if we are entering an "unsafe" state. Possible states are: 1 2 3a Deadlock : No forward progress can be made. Unsafe state : A state that may allow deadlock. Safe state: A state is safe if a sequence of processes exist such that there fare enough resources for the first to finish, and as each finishes and releases its resources there are enough for the next to finish. fa request allocation would cause an unsafe state, do not take that request Unsafe | Safe Deadlock NOTE : All deadlocks are unsafe, but all unsafe are NOT deadlocks. : a ~ In that check circular wait condition ean never exit go resource allocation stat® defined number of available and allocated resources and maximum demand fo ‘Tesources from processes. [BF opscaing System (.8se-cong a - Toavoid deadlock check following conditions: How many types of resource ? { 0 How much instances of resource ? © How resource to be allocated ? © How resources to be requested ? = This algorithm is known as Bankers Algorithm, this algorithm provide safe sequence for this algorithm it required two states : Safe state and Unsafe state. 1. Safe state : System has sufficient numberof resources. © Deadlock does not occur. © _ Baker’ algorithm provides safe sequence © Resouree allocation graph algorithm keep system in safe state. ‘Unsafe state : System can run those processes which are not required ny resource is allocated by BLOCK. © Deadlock occur. © any process require any resource invalved in deadlock that process also a part of deadlock. © Tnuunsafe state sometime system become desd, ‘© Baker's algorithm cannot provide safe sequence, For example is used exclusively by & = There exists a total of 12 resources. Bach reseuree process, The curent tate looks ik this: ce, Suppose P2 requests tn thie example, < Pi, P2, PB> is a workable emu in this example, pens eat Current Needs and is given one moresee - wrens RA BURR stew — opwarmysemawvascomy ry ae sna © e Client Name | Used | max] [enon Process Having stat | ened [Goa esos u Rahul rele Q Baban a as hk Deacock See on ee eee lava ezse( a) ‘Asha aun piel acest ‘Available (10) State A ‘Aallabe @) State B Berka’ Client Name | Used | Max. i Rahul 1_|6 Baban 2 _|s Somarth _|2_|4 Se Ashe ait ‘Available cD State = |= Keep so many resources that satisfy the needs of at least one client and multiple instances. Fig. 74.1 |= Bach process must « prio claim maximum use, When a process requests & & “reo tmay ane cer im et tha in. ieee of ft hin 5 prov gets all ts Fe G Data structures for the Banker's AlgOrHNT | Let = Number of processes: ‘This is deadlock avoidance algorithm. Example Clients are asking for loans up-to an agreed limit. =‘ Thebanker knows that not all clients need their limit simultaneously. ‘Available: Vector of tenath m- insta TFavalable []~ k tere ae ee Hee ora uric 1 Max (dl = OPP Tne, resource type Rj i then is cuetyaoatd sen of
necessarily re if ci * ner simultaneously after fulfilling their needs, the clients will pay-back their loans net! nwo sntances oft comets : a) then Pimay need km t “ The banker knows that all 4 clients need 22 units together, put he has 4 ol Need : nx mrmatrie.1F Neel] = the . Hts task, ‘location = Maxlid) = total 10 units. Need Eze. a Dh oping rem qusssccon) 7 se Fopnteg Son Scam ap Safety Algorithm , _‘Thesystem is in a safe states Step 1: Let Work and Finish be vectors of length m and n, respectively, safety criteria State since the soquence
aatistes Step 2: Initialize ; Work = Available Finish [i] = false for i= 1,2, ...,n, - Available $ Check that Request true (,9,2) thats 10,2) : Step: Find and i such that both : (a) Finish (i) Process | Allocation | Max Step 4: Ifno such i exists, go to step 4. 3. Work = Work + Allocation i = Need | Total at = true go to step 2, A|B|clalslcla]plclalplo | If Finish [i] == true for alli, then the system is in a safe state Po [o [1 fo |7[s|alzlalslalslo | Resource-Request Algorithm for Process Pl Pi__ [2 [o [o [s{alelolelo p2__|a [o [2 [o[o[2|elolo request i [j] = kmeans that process P, wants k instances of resource type Rj ae aetaaae esa olai te I request; Need} go to step 2. palo [o [2 [ala |sfala|a Executing safety algorithm shows that sequence PLS , P4 , PO , P2 satisfies safety requirement). Can request for (3,3,0) by P4 be granted ? i Otherwise, raise error condition, since process has exceeded its maximum claim. - IF request; Available, go to step 3. Otherwise P; , must wait, since resources are not! | | | | i = B processes and 3 resouree types A with 10, type B with §and type C with 7 | | available. ‘Test to allocate requested resources to P, by modifying the state as follows : | Can request for (02,0) by PO be granted? Available = Available ~ Request j; | . instances. Allocation =' Allocation+ Request | ‘Available | Process | Allocation | Max a] Needi = Need i- Request; ; | c i ae a [ple [ale i ‘If safe the resources are allocated to Pi | 2 oli lo [z[sl2 i ‘unsafe Pi must wait, and the old resource-allocation state is restored ee lelzl2 PL A Example of Banker's Algorithm ms lolz [ofolz a — 5 processes PO through PA ; 3 resource types A (10 instances), B (6 instances and | —P—ip bh felele } (7 instances), —— Tr, fo fe [2 Le 1818 pedo [recess Allocation: Max Need Total ——— ee i} alplelals[cla[sl[clapsle Js this safe state Gao | PO o |l1 lo [7 [5s [3 [7 |4 [3 |10 [5 J? | ‘Available | Proe== 5 [co [alBle i [PL 2 lo lo [5 [2 [2 [1 [2 [2 | available | s|se o {1 fo lz ists | P2 3 to [2 |9 {o [2 -[6 [o {o |7 |2 m2 foe se z | PB 2 |1 |a [2 [2 [2 [o {1 [1 | Available a 3 fo [2 [slol? 4 2 [2 PA o jo [2 [4 [3 [a [4 [3 | Js 18 P3 aade 0 jo 12 | biay peaigassmciny ire ona
is safe sequence Consider pl now request (1,0,2) ‘Available | Process [Allocation | Max | Need 2} 3}0} = A/B/C/|A/B|C/A|Blo po fo |i lo [7|5|3|7lals pi_{a [o [2 [3/2 [2/ol2 lo P2 3 jo [2 |9/o/2/6lolo rs (2 |i {a [2/2 lefoh|a pa_{o [o [2 Jalals{als[i Example 7.41: Considering a system with five processes POthrough Pé and tee resources types A, B, C. Resource type A has 10 instances, B has 5 C has 7 instances. Suppose at time 0 following instances and type iapshot of the system has been taker Allocation | Max _| Available Alpiclalaiclalaic Po _folil2i7isia/sl3l2 P, |2lololsi2l2 2 _|3}ol2ialole2 Py j2lital2l2l2 Pe folol2isialia ‘What will be the content of the Need matrix ? Need i] = Max i i] —Allocaton fj So, the content of Need Matix is: Solution : ‘Process | Need llc po [7[a[s B alal2 Pr [solo ps [ofafa PB [als[a Broreriaseensaesccony an SUERTE eee 7.43 Deadlock Detection 5 _ Write note on deadlock detection, ~ _Denlloc: detection and recovery alows deadlocks to form; thes finds and breaks them. - lf there are no prevention or avoidance mechanisms in place then deadlock may ocur. - Deadlock detection should return enough information so the OS can recover. - How often should the detection algcrithm be executed ? ~ Following are two graph method use for deadlock detection 1, Resource Allocation Graph ‘This algorithm checks whether there is any chance of deadlock or not ? This algorithm uses three types of edges. In resource allocation graph all the process can be shown into circles Resource can be shown into rectangle = Instances can he shown dots into rectangle = un QOBr opeaty gemgwasccony 8 nat ‘Request edge is from process to resource Allocation edge is from resource to process Claim edge is dotted line before request it is from process to resource Pi °2) Pe Check if any process is waiting for execution in ready state or not ? If yes then draw resource allocation graph of that process using dotted edge (claim edge) Check if any circle is there or not ? If yes then don't allow that process for execution Check whether any process required any resource or not ? If yes covert claim edge into request edge. By ogeminesytomuasccony nay resource Allocation Graph With cyl but no deadoce a, @ 9 © i @ Fig 743 request ALBA Atoatd a Atoeted p/P a tL peated Request Atoctot aga a ery @) ” - cae posted 7 FieTAa Wait-tor graph Assume that each resource Temoving the resource WP!S 200° Tor graph if the he corretlY> nodes from & Deadlock exists if and only are not dendloe- Prevention and avoidance Aetect the recover from the pas ooly one instance. or not iting for completion of some be easily converted into wait for awsitfor graph contains & deadlock may Ooo& ) 718 Danas Ri] [Fa] [Pe 5) ® e ® ? Q-O-O BE \Y = If all resource types has only single instance, then wwe can use a graph called wait-for-graph, which is a variant of resource allocation graph. - Here, vertices represent processes and a directed edge from Pl to P2 indicates that Pl is waiting for a resource held by P2. Resource allocation graph, a cycle in a wait-for-graph indicates a deadlock. So the system can maintain a wait-for-graph and check for cycles sometimes to detect any deadlocks. Fig. 745 Fig. 7.46 - Ef there are multiple instances for a resource, The Wait-for-graph is not usefl as a cycle may not imply a deadlock. In such a case, we can use an algorithm similar to Banker's algorithm to detect deadlock. Pease ees Recovery Deadlock ‘EF Expiain recovery trom deadlock. ‘This method used to recovery from deadlock and it uses deadlock detection algorithm and used to detect deadlock and find out how many processes are involved Recover for in to the deadlock. Proves Teminson ‘er One Deadocsod Process | Fig. 747 By opsnmasyem nussccong) nig ety Following is system-based recovery : [Abort one or more processes in the circular w 9 tind oom i wait preempt resources in one of 1. Process termination Abort all deadlocked processes - Abort all those process which are involved into the deadlock. Stops execution of process this technique detect how many processes are involved in the deadlock, these technique executed when system is suffering from the deadlock. ~ Find out deadlock is occurs nor not ? if yes then check total numberof involved processes in deadlock and terminates the process. Algorithm ‘Step 1 Find out deadlock occurs or not? if yes then go to step 2 ‘Step 2 : Total number of process involved in deadlock =n Step 3: Act Step 4 : Terminate process Step 5: If Aen then go to step 4 else return Abort one process at a time until the deadlocked eycle disappears- i And it detect ~ This abort one by one process tll deadlock eyle is not removing. An how many processes are involved in the deadlock. These technique is executed when system is suffering from deadlock. Aborting process means it stops execution of processes. ‘ ee enema provese js called as victim process. Ths selection proces is policy CPU scheduling. Following factor are responsible for ~ Time taken by process to complete tas ~ Type and amount of resource the proses > Number of processes are need to be terminat selection of victim process = bas used go to step 2 ese retum and ot? IF yes the Step 1: Find out whether deadlock eee Slep 2 Let n i total number of invlved POSS Step 3 :, select victim process using above HP 4: Terminate the victim process omr EES SEES Wee ee ‘Step 5 = Check deadlock cycle is terminated or not ? If yes then return aa ay Resco, | Eise go to step 6 Step 6: A= Att }| gt Astateis if tho system can allocate re Step 7: If Acon then go to step 3 else select victim process and delete it. | esta wold toca sources foreach process in some onder 2. Resource pre-emption a2 Each process in a system has a segment of cove, ae ~ Ifprocesses are not getting required resources it going on deadlock state process may be changing common vrbles, updating ease een ee = Hence it preempts required resource from the process who holding it , wring ale. Following three issues need to be address. 1. Selecting victim : Select process as (0.3, _____Is a segment of code in system process in which he process may be changing ‘common variables, updating a table, witng a flo, and so on. tim process with following | criteria: os ae the handing method for descock © Selection is depend on cost factor of the process. Q.5 Instance are shown by using © Number of resources holding by that process. €.8 What are the deaclock condone? © Number of process waiting for resources holding by process. ib estinies coment oelame creseorta 0.7, What are the methods for handing deadlocks sales? © Number of time deadlock is occurred during execution, | How can wa peavent She occurrence a < deed coos 2, Rollback : When one process is selected as victim then it could not 0.9 How can we avoiding deadlocks occur? continue its normal execution because all ite resources are preempted ; . tect from it, so keep such process in safe state and when deadlock is learedit_ © '0 Extlaln he deadlock detection restarts that process from safe state, that known as Rollback. | 2.11 How can recavery fram dosdlock state? ; : | Starvation : When some process is selected as victim process again and | 0.12 Write short note on deadlock. again is known as Starvation because of starvation some process i nat 0.13 Explain wait resouree allocation graph. able to complete its desi : a Jock, Mutual excusion, Hold and Wat, No Preemption, Ccular Algorithm .14 Define Starvation, dead ‘Step 1 : Find out whether deadlock is present or not ? If yes then go to step 2 else return Wait, Step 2: Let nis total number of involved processes in deadlock and At Step 3: Select victim process using cost factor Step 4 Change the current state of process to safe state and rollback Step 5: Preempts all resources from that process. Step 6 : Check deadlock is over or not ? if yes retum else go to step 7 Step 7: A=A+1 ‘Step 8 : If A
You might also like
Process Scheduling
PDF
No ratings yet
Process Scheduling
16 pages
Chapter No:04 CPU Scheduling and Algorithms Total Marks:14: Mr. C. R. Ghuge
PDF
No ratings yet
Chapter No:04 CPU Scheduling and Algorithms Total Marks:14: Mr. C. R. Ghuge
43 pages
Unit 4 OSY Presentation
PDF
No ratings yet
Unit 4 OSY Presentation
37 pages
Processor Scheduling
PDF
No ratings yet
Processor Scheduling
35 pages
Chap 3 Process Scheduling
PDF
No ratings yet
Chap 3 Process Scheduling
53 pages
OS Process CPU Scheduling
PDF
No ratings yet
OS Process CPU Scheduling
49 pages
1709286746_1
PDF
No ratings yet
1709286746_1
73 pages
Chapter 4
PDF
No ratings yet
Chapter 4
56 pages
1738217635590890
PDF
No ratings yet
1738217635590890
32 pages
Government Polytechnic Jintur: Department of Computer Engg
PDF
No ratings yet
Government Polytechnic Jintur: Department of Computer Engg
55 pages
OS Chapter-5-CPU schediling
PDF
No ratings yet
OS Chapter-5-CPU schediling
49 pages
Chapter 6: CPU Scheduling
PDF
No ratings yet
Chapter 6: CPU Scheduling
57 pages
Module 2
PDF
No ratings yet
Module 2
44 pages
Scheduling
PDF
No ratings yet
Scheduling
23 pages
OS 02 Customized 1
PDF
No ratings yet
OS 02 Customized 1
66 pages
1207505202 CPU Scheduling
PDF
No ratings yet
1207505202 CPU Scheduling
17 pages
Os Chapter 4
PDF
No ratings yet
Os Chapter 4
16 pages
Unit 2
PDF
No ratings yet
Unit 2
39 pages
Process Scheduling - Module2
PDF
No ratings yet
Process Scheduling - Module2
61 pages
Unit 3.4 Process Scheduling
PDF
No ratings yet
Unit 3.4 Process Scheduling
57 pages
1 - OS Process CPU Scheduling
PDF
No ratings yet
1 - OS Process CPU Scheduling
34 pages
unit4
PDF
No ratings yet
unit4
63 pages
Chapter - 4 OSY by PSG
PDF
No ratings yet
Chapter - 4 OSY by PSG
43 pages
Wa0081.
PDF
No ratings yet
Wa0081.
32 pages
CpuScheduling CS
PDF
No ratings yet
CpuScheduling CS
81 pages
Unit IV - CPU Scheduling and Algorithm Section 4.1 Scheduling Types Scheduling Objectives
PDF
No ratings yet
Unit IV - CPU Scheduling and Algorithm Section 4.1 Scheduling Types Scheduling Objectives
18 pages
Os Unit Ii
PDF
No ratings yet
Os Unit Ii
6 pages
Schedulingalgorithms and Algorithm Evaluation
PDF
No ratings yet
Schedulingalgorithms and Algorithm Evaluation
38 pages
Chapter 5: CPU Scheduling: Silberschatz, Galvin and Gagne ©2009 Operating System Concepts - 8 Edition
PDF
No ratings yet
Chapter 5: CPU Scheduling: Silberschatz, Galvin and Gagne ©2009 Operating System Concepts - 8 Edition
26 pages
OS 02 Customized
PDF
No ratings yet
OS 02 Customized
66 pages
Schedulers
PDF
No ratings yet
Schedulers
30 pages
Process Scheduling
PDF
No ratings yet
Process Scheduling
80 pages
5 Cpu Scheduling
PDF
No ratings yet
5 Cpu Scheduling
33 pages
Scheduling
PDF
No ratings yet
Scheduling
29 pages
CPU Scheduling and Process Management
PDF
No ratings yet
CPU Scheduling and Process Management
5 pages
Chapter 4
PDF
No ratings yet
Chapter 4
23 pages
Process Scheduling Report
PDF
No ratings yet
Process Scheduling Report
6 pages
COSC 823 Lecture Slide -2
PDF
No ratings yet
COSC 823 Lecture Slide -2
45 pages
Chapter-3 CPU Scheduling
PDF
No ratings yet
Chapter-3 CPU Scheduling
65 pages
OS UNIT-II
PDF
No ratings yet
OS UNIT-II
24 pages
5 OS CPUscheduling
PDF
No ratings yet
5 OS CPUscheduling
29 pages
CPU Scheduling and Algorithm
PDF
No ratings yet
CPU Scheduling and Algorithm
18 pages
Unit-2_84beee2a43c1be02b5032b4a14f7ee28
PDF
No ratings yet
Unit-2_84beee2a43c1be02b5032b4a14f7ee28
76 pages
Cpu Scheduling
PDF
No ratings yet
Cpu Scheduling
62 pages
OS-Module2.2-Process Scheduling
PDF
No ratings yet
OS-Module2.2-Process Scheduling
93 pages
Scheduling
PDF
No ratings yet
Scheduling
44 pages
Unit 2
PDF
No ratings yet
Unit 2
30 pages
CPU Scheduling and Algorithm Question Solution
PDF
No ratings yet
CPU Scheduling and Algorithm Question Solution
16 pages
Unit IV OSY Handout Revised 07.08.2023
PDF
No ratings yet
Unit IV OSY Handout Revised 07.08.2023
33 pages
CPU Scheduling
PDF
No ratings yet
CPU Scheduling
36 pages
Skill Paper III Unit
PDF
No ratings yet
Skill Paper III Unit
24 pages
Unit 4 OSY
PDF
No ratings yet
Unit 4 OSY
62 pages
Process Scheduling
PDF
No ratings yet
Process Scheduling
50 pages
05 - CPU Scheduling
PDF
No ratings yet
05 - CPU Scheduling
15 pages
FILE4 CPU SCHEDULING
PDF
No ratings yet
FILE4 CPU SCHEDULING
17 pages
Cpu Scheduling
PDF
No ratings yet
Cpu Scheduling
36 pages
CPU Scheduling
PDF
No ratings yet
CPU Scheduling
77 pages
CPU Scheduling
PDF
No ratings yet
CPU Scheduling
63 pages