Presentation is loading. Please wait.

Presentation is loading. Please wait.

P ROCESSES S CHEDULING Prepared By: Dr. Vipul Vekariya.

Similar presentations


Presentation on theme: "P ROCESSES S CHEDULING Prepared By: Dr. Vipul Vekariya."— Presentation transcript:

1 P ROCESSES S CHEDULING Prepared By: Dr. Vipul Vekariya

2 S CHEDULING An OS must allocate resources amongst competing processes. The resource provided by a processor is execution time The resource is allocated by means of a schedule

3 S CHEDULING O BJECTIVES The scheduling function should Share time fairly among processes Prevent starvation of a process Use the processor efficiently Have low overhead Prioritise processes when necessary (e.g. real time deadlines)

4 T YPES OF SCHEDULING Long-Term Scheduling Medium-Term Scheduling Short-Term Scheduling 4

5 L ONG -T ERM S CHEDULING Determines which programs are admitted to the system for processing May be first-come-first-served Or according to criteria such as priority, I/O requirements or expected execution time Controls the degree of multiprogramming More processes, smaller percentage of time each process is executed

6 M EDIUM -T ERM S CHEDULING Part of the swapping function Swapping-in decisions are based on the need to manage the degree of multiprogramming

7 S HORT -T ERM S CHEDULING Known as the dispatcher Executes most frequently Invoked when an event occurs Clock interrupts I/O interrupts Operating system calls Signals

8 T YPES OF S CHEDULING

9 S CHEDULING AND P ROCESS S TATE T RANSITIONS

10 Q UEUING D IAGRAM

11 Bursts of CPU usage alternate with periods of waiting for I/O. (a) A CPU-bound process. (b) An I/O-bound process. Scheduling – Process Behavior

12 N ONPREEMPTIVE VS P REMEPTIVE Non-preemptive Once a process is in the running state, it will continue until it terminates or blocks itself for I/O Preemptive Currently running process may be interrupted and moved to ready state by the OS Preemption may occur when new process arrives, on an interrupt, or periodically.

13 C RITERIA FOR S CHEDULING Fairness : this goal is important under all circumstance. A scheduler makes sure that each process gets its fair share of CPU. Efficiency : scheduler should keep the system, busy all time, when possible. Response time : this measure is the time from the submission of the request till the first response is produced. Waiting time : Amount of time a process spends waiting in ready queue. The waiting time should be minimum. Turnaround time : the interval from the time of submission of the process to the time of completion of the process is the turnaround time. Throughput : is the measure of the work done by the CPU. CPU utilization : CPU utilization can have value in the range of 0 to 100%. 13

14 P ROCESS S CHEDULING E XAMPLE Example set of processes, consider each a batch job – Service time represents total execution time

15 F IRST -C OME - F IRST -S ERVED Process are assigned to CPU in the order they came or submitted.

16 FIFO Also known as F irst C ome, F irst S erved (FCFS), its the simplest scheduling algorithm, FIFO simply queues processes in the order that they arrive in the ready queue.FIFO Since context switches only occur upon process termination, and no reorganization of the process queue is required, scheduling overhead is minimal. Throughput can be low, because long processes can hold the CPU Turnaround time, waiting time and response time can be low for the same reasons above No prioritization occurs, thus this system has trouble meeting process deadlines. The lack of prioritization does permit every process to eventually complete, hence no starvation. 16

17 G ANTT C HART. ABCDE 17 0 3 9 13 18 20 Waiting timeProcess 0A 3 – 2 = 1B 9 – 4 = 5C 13 – 6 = 7D 18 – 8 = 10E Average waiting time Average waiting time = 0+1+5+7+10 = 4.6ms

18 SJF(S HORTEST JOB FIRST ) Also known as S hortest J ob F irst (SJF). With this strategy the scheduler arranges processes with the least estimated processing time remaining to be next in the queue If a shorter process arrives during another process' execution, the currently running process may be interrupted, dividing that process into two separate computing blocks. This creates excess overhead through additional context switching. This algorithm is designed for maximum throughput in most scenarios. Overall waiting time is smaller than FIFO, however since no process has to wait for the termination of the longest process. No particular attention is given to deadlines. Starvation is possible, especially in a busy system with many small processes being run. 18

19 S HORTEST JOB FIRST It is non preemptive or preemptive kind of algorithm in which waiting job with the smallest estimated runtime to completion run next. 19 Waiting timeProcess 0A 3 – 2=1B 11 – 4 =7C 15 – 6 = 11D 9 – 8 = 1E Average waiting time = 0+1+7+11+1/5 = 4ms ABECD 0 3 9 11 15 20

20 SJF WITH PREEMPTIVE ( SHORTEST R EMAINING NEXT ) 20 Waiting timeProcess 0A 10 – (1+2) =7B 4 – 4 =0C 15 – 6 = 11D 8 – 8 = 0E Average waiting time = 0+7+0+11+0/5 = 3.6ms ABCEBD 0 3 4 8 10 15 20

21 SJF WITH PREEMPTIVE ( SHORTEST R EMAINING NEXT ) ProcessArrival timeBurst time P108 P214 P329 P435 21 Waiting timeprocess (10 -1) =9P1 (1-1)=0P2 (17-2) =15P3 (5-3) =2P4 Average waiting time = 9+0+15+2/4 = 6.5ms

22 P RIORITY SCHEDULING ( PREEMPTIVE ) Overhead is not minimal, nor is it significant. It has no particular advantage in terms of throughput over FIFO scheduling. Waiting time and response time depend on the priority of the process. Higher priority processes have smaller waiting and response times. Deadlines can be met by giving processes with deadlines a higher priority. Starvation of lower priority processes is possible with large amounts of high priority processes queuing for CPU time. 22

23 P RIORITY SCHEDULING. 23 ProcessBurst timePriority P1103 P211 P323 P414 P552 Waiting timeprocess 6P1 0P2 16P3 18P4 1P5 Average waiting time = 6+0+16+18+1/5 = 8.2ms

24 R OUND R OBIN S CHEDULING Specially for time sharing system. A small unit called time slice is defined. It is also called Quantum. The ready queue treated as a circular queue. 24 ProcessBurst time P124 P23 P33

25 RR S CHEDULE If there is n process in the ready queue and time slice is q, then each process gets of the CPU time in chunks at most q times units. Each process must wait no longer than (n-1)*q times until its next time slice. Context switch is the main problem with this algorithm. Conclusion can be formulated as follows: Setting quantum too short causes too many process switches and lower the CPU efficiency. Setting large quantum may cause poor response to short request. A quantum around 20-25 msec is good for algorithm 25

26 R OUND R OBIN SCHEDULE RR scheduling involves extensive overhead, especially with a small time unit. Balanced throughput between FCFS and SJF, shorter jobs are completed faster than in FCFS and longer processes are completed faster than in SJF. Fastest average response time, waiting time is dependent on number of processes. Because of high waiting times, deadlines are rarely met in a pure RR system. Starvation can never occur, since no priority is given. 26

27 C OMPARISON OF SCHEDULING ALGORITHM 27 Scheduling algorithm CPUCPUUtiliz ation Throughp ut Turnaroun d time Response time DeadlineDeadlineh andling StarvationStarvation free First In First Out Low HighLowNoYes Shortest Job First MediumHighMedium No priority pre- emptive scheduling MediumLowHigh YesNo Round- robin scheduling HighMedium HighNoYes


Download ppt "P ROCESSES S CHEDULING Prepared By: Dr. Vipul Vekariya."

Similar presentations


Ads by Google