Chapter 5 102 II

Embed Size (px)

Citation preview

  • 8/2/2019 Chapter 5 102 II

    1/25

    SPRING 2011 - 1021

  • 8/2/2019 Chapter 5 102 II

    2/25

    Deciding which process/thread should use a Resource

    (CPU, disc, etc.)

    SPRING 2011 - 102

    2

  • 8/2/2019 Chapter 5 102 II

    3/25

    SPRING 2011 - 1023

  • 8/2/2019 Chapter 5 102 II

    4/25

    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.

    NonPreemptive

    Pre-emptive

    A Non preemptive

    priority schedulingalgorithm will simply

    put the new process

    at the tail of the

    Ready Queue.

    A Preemptive priority

    scheduling algorithm will

    preempt the CPU if thepriority of the newly arrived

    process is higher than the

    priority of the currently

    running process..

    SPRING 2011 - 102

    4

  • 8/2/2019 Chapter 5 102 II

    5/25

    SPRING 2011 - 102

    5

    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

  • 8/2/2019 Chapter 5 102 II

    6/25

    SPRING 2011 - 102

    6

  • 8/2/2019 Chapter 5 102 II

    7/25

    SPRING 2011 - 102

    7

  • 8/2/2019 Chapter 5 102 II

    8/25SPRING 2011 - 1028

  • 8/2/2019 Chapter 5 102 II

    9/25

    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 readyqueue

    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

    9

  • 8/2/2019 Chapter 5 102 II

    10/25

    Process Burst Time

    P1 53

    P2

    17

    P3 68

    P4 24

    The Gantt chart is:

    Typically, higher average turnaround than SJF, but better response

    P1 P2 P3 P4 P1 P3 P4 P1 P3 P3

    0 20 37 57 77 97 117 121 134 154 162

    Time Quantum = 20

    SPRING 2011 - 102

    10

  • 8/2/2019 Chapter 5 102 II

    11/25

    19 APRIL 2011 COPYRIGHT VIRTUAL UNIVERSITY OF PAKISTAN

    Process Burst TimeP1

    53 33 13P2

    17

    P3 68

    48

    28

    8P4

    24 4

    The Gantt chart with quantum 20 is:

    P1 P2 P3 P4 P1 P3 P4 P1 P3 P3

    0 20 37 57 77 97 117 121 134 154 162

  • 8/2/2019 Chapter 5 102 II

    12/25

    19 APRIL 2011

    Process Turnaround Time Waiting Time

    P1 134 134

    53 = 81P2

    37 37 17 = 20

    P3

    162 162 68 = 94

    P4

    121 121 24 = 97

    Average waiting time = 73

  • 8/2/2019 Chapter 5 102 II

    13/25

    SPRING 2011 - 102

    13

  • 8/2/2019 Chapter 5 102 II

    14/25

    SPRING 2011 - 102

    14

  • 8/2/2019 Chapter 5 102 II

    15/25

    Very large quantum size

    Processes run for long periods

    Degenerates to FIFO

    Very small quantum size

    System spends more timecontext switching than runningprocesses

    Quantum size

    SPRING 2011 - 102

    15

  • 8/2/2019 Chapter 5 102 II

    16/25

    Quantum size

    Best quantum time size

    Depends on system

    Interactive: response time key factor

    Batch: turnaround time key factor

    SPRING 2011 - 102

    16

  • 8/2/2019 Chapter 5 102 II

    17/25

    SPRING 2011 - 10217

  • 8/2/2019 Chapter 5 102 II

    18/25

    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 scheduleamongst its processes; i.e., 80% to foreground in RR 20% to background in FCFS

  • 8/2/2019 Chapter 5 102 II

    19/25

  • 8/2/2019 Chapter 5 102 II

    20/25

    SPRING 2011 - 10220

  • 8/2/2019 Chapter 5 102 II

    21/25

    Different processes have different needs

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

    Multilevel feedback queues

    Arriving processes enter the highest-level queue andexecute with higher priority than processes in lowerqueues

    Long processes repeatedly descend into lower levels

    Gives short processes and I/O-bound processes higherpriority

    Long processes will run when short and I/O-boundprocesses terminate

    Processes in each queue are serviced using round-robin

    Process entering a higher-level queue preempt running

    processes

  • 8/2/2019 Chapter 5 102 II

    22/25

    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

  • 8/2/2019 Chapter 5 102 II

    23/25

    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 ismoved to queue Q1.

    At Q1job is again served FCFS and receives 16 additional milliseconds. Ifit still does not complete, it is preempted and moved to queue Q2.

  • 8/2/2019 Chapter 5 102 II

    24/25

    SPRING 2011 - 102

    24

  • 8/2/2019 Chapter 5 102 II

    25/25

    SPRING 2011 - 102

    25