Presentation is loading. Please wait.

Presentation is loading. Please wait.

Operating Systems (CSCI2413) Lecture 4 Process Scheduling phones off (please)

Similar presentations


Presentation on theme: "Operating Systems (CSCI2413) Lecture 4 Process Scheduling phones off (please)"— Presentation transcript:

1 Operating Systems (CSCI2413) Lecture 4 Process Scheduling phones off (please)

2 © De Montfort University, 2004CSCI2413 - L42 Overview Scheduling objectives and criteria –Pre-emptive v. non-pre-emptive scheduling – criteria Scheduling algorithms –first come first served –shortest job first –round robin –priority queues

3 © De Montfort University, 2004CSCI2413 - L43 Scheduling Objectives When more than one process is in the ready state OS must decide which one to run first –this decision is made by the scheduler There are many ways in which the operating system can actually make the choice –the method of choice is the scheduling algorithm If OS switches processes often the context switch may take up too much time. –the processor spends more time switching processes than actually running any of them!

4 © De Montfort University, 2004CSCI2413 - L44 Scheduling Classes Two major classes of scheduling: –non-pre-emptive process runs until it drops or blocked –pre-emptive process interrupted by the OS and moved to ready state

5 © De Montfort University, 2004CSCI2413 - L45 Non-pre-emptive Scheduling A running process may only move to the blocked state by choosing to do so itself –by asking for resource (e.g. user input) or simply passing control back to operating system to be ‘nice’ –if a process is occupying the processor (e.g. doing a long calculation) then it continues running Windows 3.1 works like this ready running blocked these state changes only come about by the process initiating them resource request process ‘pause’

6 © De Montfort University, 2004CSCI2413 - L46 Pre-emptive Scheduling A running process may move itself to the blocked state or may be moved there automatically by the operating system –a clock timer causes a hardware interrupt to stop the process and return control to the operating system Windows NT and UNIX work like this ready running blocked resource request this state change can occur through a system clock interrupt clock interrupt

7 © De Montfort University, 2004CSCI2413 - L47 Criteria What criteria should a good scheduling algorithm have? fairness giving each process a fair share of the CPU efficiency keep the processor busy and useful all the time response time minimise response times for interactive users turnaround minimise the time batch users must wait for output throughput maximise the jobs processed per hour

8 © De Montfort University, 2004CSCI2413 - L48 You Can’t Please them all! It is not possible to satisfy all these criteria at the same time –consider minimising the response time so whenever an interactive user submits a process to the queue it should start immediately but this may interrupt another job that is just about to finish, which therefore increases its turnaround time A job that is considered not very important (e.g. a system task such as a virus scanner) may never get any time if interactive users are waiting –this violates the first criteria: ‘fairness’

9 Scheduling Algorithms

10 © De Montfort University, 2004CSCI2413 - L410 Performance Measures What is the best choice of scheduling algorithm when designing an operating system? –need some measures of algorithm performance Two simple measures are –average response time an average of the time taken for all the processes in an example process queue to start –average turnaround time an average of the time taken for all the processes in an example process queue to finish

11 © De Montfort University, 2004CSCI2413 - L411 First Come First Served (FCFS) The process scheduler starts the processes in the order that they entered the queue –the first process to enter the queue is run first it continues to run until it has finished –the next process is run until it finishes and so on FCFS is a non-pre-emptive algorithm –once a process starts, it does not get interrupted by the operating system and continues until it finishes

12 © De Montfort University, 2004CSCI2413 - L412 01234567891011121314151617181920 CPU Process Queue C length=6 priority=1 B length=2 priority=2 A length=7 priority=3 D length=5 priority=1 FCFS Simulation Average response= AAAAAAA A length=7 priority=3 BB B length=2 priority=2 CCCCCC C length=6 priority=1 DDDDD D length=5 priority=1 0 7Average turn round= + 7 + 9 + 15 + 20 = 31 / 4 = 7.75 = 51 / 4 = 12.75

13 © De Montfort University, 2004CSCI2413 - L413 Shortest Job First (SJF) The operating system considers the known or estimated length of each process –the processes are started in order of shortest one first a process continues until it has finished –the next shortest process is run until is has finished and so on SJF is also a non-pre-emptive algorithm –once a process starts, it does not get interrupted by the operating system and continues until it finishes –the length must be known (or a good estimate)

14 © De Montfort University, 2004CSCI2413 - L414 SJF Simulation 01234567891011121314151617181920 CPU Process Queue C length=6 priority=1 B length=2 priority=2 A length=7 priority=3 D length=5 priority=1 BB B length=2 priority=2 DDDDD D length=5 priority=1 CCCCCCA C length=6 priority=1 AAAAAA A length=7 priority=3 Average response=0 2Average turn round= + 2 + 7 + 13 + 20 = 22 / 4 = 5.5 = 42 / 4 = 10.5

15 © De Montfort University, 2004CSCI2413 - L415 Round Robin (RR) Each process is given a time slice in the order that they appeared into the queue –when the time slice is finished, the process is interrupted and the next process runs As each process finishes it is deleted from the queue and the round robin continues to the next RR is a pre-emptive algorithm –processes are interrupted by the operating system It is very important to balance the amount of time allocated for each time slice with the time taken to switch processes (the context switch)

16 © De Montfort University, 2004CSCI2413 - L416 RR Simulation 01234567891011121314151617181920 CPU Process Queue C length=6 priority=1 B length=2 priority=2 A length=7 priority=3 D length=5 priority=1 ABCDABCD B length=2 priority=2 ACDACDACD D length=5 priority=1 AC C length=6 priority=1 A A length=7 priority=3 Average response=0 6Average turn round= + 1 + 17 + 2 + 19 + 3 + 20 = 6 / 4 = 1.5 = 62 / 4 = 15.5

17 © De Montfort University, 2004CSCI2413 - L417 Priority Queues (PQ) So far, no algorithm has utilised the priority field –this indicates to the operating system how important the job is considered to be In the priority queue algorithm processes are run in order of importance –highest priority runs first note: most important process has the lowest priority number priority=1 means the ‘first priority’ –processes with equal priority use round robin algorithm PQ is also a pre-emptive algorithm –processes are interrupted by the operating system

18 © De Montfort University, 2004CSCI2413 - L418 PQ Simulation 01234567891011121314151617181920 CPU Process Queue C length=6 priority=1 B length=2 priority=2 A length=7 priority=3 D length=5 priority=1 CDCDCD C length=6 priority=1 CDC B length=2 priority=2 DCBB D length=5 priority=1 AAAAAAA A length=7 priority=3 Average response=0 10Average turn round= + 1 + 11 + 13 + 20 = 25 / 4 = 6.25 = 54 / 4 = 13.5

19 © De Montfort University, 2004CSCI2413 - L419 Analysis of Scheduling Algorithms For this example process queue algorithmresponseturnaroundtotal FCFS7.7512.7520.5 SJF5.510.516.0 RR1.515.517.0 PQ6.2513.519.75 SJF will always have minimum turnaround time –best suited for batch systems where the process length is known or can be well estimated RR will always have the minimum response time –suited for interactive systems where users tend to expect something to happen as soon as possible

20 © De Montfort University, 2004CSCI2413 - L420 Dynamic Priority Queues Most modern interactive operative systems use a variety of the priority queue –the priority of each process starts off the same sometimes the user is allowed to be particularly nice to everyone else by deliberately lowering a process priority –process priorities are changed by the operating system according to the amount of processor time they use (as opposed to input/output operations) e.g. high processor usage gets low priority This is called dynamic priority queues –used in UNIX and Windows NT

21 © De Montfort University, 2004CSCI2413 - L421 Summery Scheduling objectives and criteria –Pre-emptive v. non-pre-emptive scheduling – criteria Scheduling algorithms –first come first served –shortest job first –round robin –priority queues


Download ppt "Operating Systems (CSCI2413) Lecture 4 Process Scheduling phones off (please)"

Similar presentations


Ads by Google