Sie sind auf Seite 1von 25

1

SPRING 2011 - 102

Deciding which process/thread should use a Resource (CPU, disc, etc.)

SPRING 2011 - 102

SPRING 2011 - 102

A priority number (integer) is associated with each process The CPU is allocated to the process with the highest priority (smallest integer highest priority) A priority scheduling algorithm can be preemptive or non preemptive.
A Preemptive priority scheduling algorithm will preempt the CPU if the priority of the newly arrived process is higher than the priority of the currently running process..
SPRING 2011 - 102

A Non preemptive priority scheduling algorithm will simply put the new process at the tail of the Ready Queue.

Non Preemptive

Preemptive

SJF is a priority scheduling where priority is the predicted next CPU burst time.

Problem Starvation
low priority processes may never execute

Solution Aging
as time progresses increase the priority of the process

SPRING 2011 - 102

SPRING 2011 - 102

SPRING 2011 - 102

SPRING 2011 - 102

Round-robin scheduling
Pre emptive

Based on FIFO time slice or quantum

Processes run only for a limited amount of time . After this time has elapsed, the process is preempted and added to the end of the ready queue

If there are n processes in the ready queue and the time quantum is q, then each process gets 1/n of the CPU time in chunks of at most q time units at once. No process waits more than (n-1)q time units.
SPRING 2011 - 102

10

Process
P1 P2 P3 P4

Burst Time
53 17 68 24
Time Quantum = 20

The Gantt chart is:


P1 0 20 P2 37 P3 57 P4 77 P1 97 P3 117 P4 P1 121 134 P3 P3 154 162

Typically, higher average turnaround than SJF, but better response


SPRING 2011 - 102

Process P1 P2 P3 P4

Burst Time 53 33 13 17 68 48 28 8 24 4

The Gantt chart with quantum 20 is:


P1 0 20 P2 37 P3 57 P4 77 P1 97 P3 117 P4 P1 121 134 P3 P3 154 162

COPYRIGHT VIRTUAL UNIVERSITY OF PAKISTAN

19 APRIL 2011

Process
P1 P2 P3 P4

Turnaround Time
134 37 162 121

Waiting Time
134 53 = 81 37 17 = 20 162 68 = 94 121 24 = 97

Average waiting time = 73

19 APRIL 2011

13

SPRING 2011 - 102

14

SPRING 2011 - 102

15

Quantum size
Very large quantum size
Processes run for long periods Degenerates to FIFO

Very small quantum size


System spends more time context switching than running processes

SPRING 2011 - 102

16

Quantum size

Best quantum time size

Depends on system

Interactive: response time key factor Batch: turnaround time key factor

SPRING 2011 - 102

17

SPRING 2011 - 102

Ready queue is partitioned into separate queues:


foreground (interactive) background (batch)

Each queue has its own scheduling algorithm


foreground RR background FCFS

Scheduling must be done between the queues

Fixed priority scheduling; (i.e., serve all from foreground then from background). Possibility of starvation. Time slice each queue gets a certain amount of CPU time which it can schedule amongst its processes; i.e., 80% to foreground in RR 20% to background in FCFS

20

SPRING 2011 - 102

Different processes have different needs

Short I/O-bound interactive processes should generally run before processor-bound batch processes

Multilevel feedback queues

Arriving processes enter the highest-level queue and execute with higher priority than processes in lower queues

Long processes repeatedly descend into lower levels


Gives short processes and I/O-bound processes higher priority Long processes will run when short and I/O-bound processes terminate

Processes in each queue are serviced using roundrobin

Process entering a higher-level queue preempt running processes

Similarly Aging can be done to prevent starvation i.e. the processes that waits too long in the lower priority queue are moved to a higher priority queue Multilevel-feedback-queue scheduler defined by the following parameters:

number of queues
scheduling algorithms for each queue method used to determine when to upgrade a process method used to determine when to demote a process method used to determine which queue a process will enter when that process needs service

Three queues:

Q0 RR with time quantum 8 milliseconds Q1 RR time quantum 16 milliseconds Q2 FCFS

Scheduling

A new job enters queue Q0 which is served FCFS. When it gains CPU, job receives 8 milliseconds. If it does not finish in 8 milliseconds, job is moved to queue Q1.
At Q1 job is again served FCFS and receives 16 additional milliseconds. If it still does not complete, it is preempted and moved to queue Q2.

24

SPRING 2011 - 102

25

SPRING 2011 - 102

Das könnte Ihnen auch gefallen