cpu scheduling algorithms

Download CPU Scheduling algorithms

If you can't read please download the document

Upload: shanu-kumar

Post on 16-Apr-2017

3.418 views

Category:

Education


0 download

TRANSCRIPT

Sikkim Manipal University

By:- Shanu Kumar Alpana GuptaJanu Kumar

1

Maximum CPU utilization obtained with multiprogramming.

Scheduling :- A method of assigning CPU to a process.

Scheduling is the basis of multi-programmed OS.BASIC CONCEPTS

2

PROCESS EXECUTION

3

CPU I/O BURST CYCLE

4

A module that selects a process, for assigning CPU to it .

It Involves 2 Steps :- Switching Context. Jumping to the proper location in the program to re-start the program. Dispatch Latency :- Time it takes for the dispatcher to stop one process and start another running.DISPATCHER

5

Non-Preemptive Scheduling Once A process is allocated the CPU, it does not leave unless :- It has to wait for an I/O request. It terminates. Preemptive Scheduling OS can force (preempt) A process from CPU at anytime. For example :- To allocate CPU to another higher priority processes. Due to end of time slice. WAYS OF SCHEDULING

6

When A process switches from the running state to waiting state ( due to an I/O request ).

When A process switches from the running state to ready state ( due to end of time slice ).

When A process switches from the waiting state to ready state ( at completion of I/O ).

When A process terminates.

CPU SCHEDULER

7

CPU Utilization Keep the CPU as busy as possible.

Throughput Number of processes that complete their execution per time unit.

Turnaround Time Amount of time to execute A particular process.

Waiting Time Amount of time A process has been waiting in the ready queue.

Response Time Amount of time it takes from when A request was submitted until the first response is produced, not output (for time-sharing environment).

SCHEDULING CRITERIA

8

TYPES OF CPU SCHEDULING ALGORITHM

First-Come-First-Served Scheduling Round-Robin Scheduling Priority Scheduling Shortest-Job-First Scheduling

9

FIRST-COME-FIRST-SERVED Simplest algorithm. Non-preemptive. Processes assigned in the order they request. Single queue of ready processes . FIFO queue structure. When the process joins the ready queue , it is linked to the tail of the FIFO queue. When the CPU is idle, the process at the head of the FIFO queue is allocated to the CPU and deleted from the queue.

10

Process Burst Time(ms) P1 24 P2 3 P3 3

P1 P2 P3

0242730Average waiting time = 3 msAverage turnaround time = 13 ms P2 P3 P1

03630Chart 1Average waiting time = 17 msAverage turnaround time = 27 ms Chart 2

FIRST-COME-FIRST-SERVED

11

ADVANTAGES Easy to understand. Easy to program. Single queue keeps track of all ready processes. Picking a process to run, just requires removing one from the head of the queue. Adding a new process or unblocked process just requires attaching it to the tail of the queue.

FIRST-COME-FIRST-SERVED

12

The average waiting time is often quite long . Its average waiting time varies if the CPU burst times vary greatly. Small process wait for one big process. Not suited for time sharing systems. DISADVANTAGES FIRST-COME-FIRST-SERVED

13

Designed for time sharing systems. Preemptive. Process assigned a time interval, called quantum. CPU scheduler allocates each process in the ready queue one time slice at a time. Follow FIFO queue structure. Processes allocated to the CPU may have the current CPU burst:-

In first two cases, process will release the CPU by its own. In the third case, the current process is preempted.

equal to the time slice smaller than the time slice greater than the time slice ROUND - ROBIN

14

Process Burst time (ms) P1 24 P2 3 P3 3

Duration of time slice = 4 ms P1 P2 P3 P1 P1 P1 P1 P1

047101418222630Waiting time, P1 = 0 + (10 4) P2 = 4 P3 = 7

Average waiting time = 17/3 = 5.66 msROUND - ROBIN

15

Simple and easy to implement. Each processes get equal chance to execute. Handling all processes without priority. Starvation free.ROUND - ROBIN Depend upon the length of the time slice. Same as FCFS, if time slice is indefinitely large. Small time slice will deteriorates due to frequent context switching.

ADVANTAGES DISADVANTAGES

16

PRIORITY SCHEDULING A priority number (integer) is associated with each process. Smallest integer Highest priority. The CPU is allocated to the process with highest priority. Can be Preemptive or Non-preemptive. Equal priority processes are scheduled on FCFS.

17

Process Priority Burst time (ms) P1 3 10 P2 1 1 P3 3 2 P4 4 1 P5 2 5

P2 P5 P1 P3 P4

016161819Chart 1Average waiting time = (6+0+16+18+1) / 5 = 41/5 =8.2 ms

PRIORITY SCHEDULING

18

PRIORITY SCHEDULING

DISADVANTAGES If system eventually crashes, all low priority processes get lost. Indefinite blocking or Starvation.ADVANTAGES Aging :- As time increases , increase in the priority of a process. Simplicity. Suitable for applications with varying time and resource requirement.

19

SHORTEST JOB FIRST Length of CPU burst of each process is considered. Process with the smallest CPU burst, will be executed first. In case of tie between processes, FCFS is used. SJF is optimal :- Gives minimum average waiting time for a given set of processes.

20

ProcessArrival time (ms)Burst time (ms) P1 0 8 P2 1 4 P3 2 9 P4 3 5

SJF Preemptive Scheduling, P1 P2 P4 P1 P3

015101726Average waiting time = 6.5 ms SJF Non-preemptive scheduling, P1 P2 P4 P3

08121726Average waiting time = 7.75 msChart 2Chart 1SHORTEST JOB FIRST

21

SHORTEST JOB FIRST ADVANTAGES DISADVANTAGES Accurate length of CPU burst is not known. Some risk of Starvation for longer processes. Produces the minimum average turnaround time. Reduces average waiting time.

22

24