SlideShare a Scribd company logo
1 of 56
The OS as a time keeper
Scheduling
   In multiprogramming systems, the OS
    decides which one to activate when there is
    more than one runnable process (in the ready
    queue).

   The decision is made by the part of the OS
    called scheduler using a scheduling
    algorithm.
Scheduling
   Set of policies and mechanisms to control the
    order of work to be performed by a computer
    system.
Scheduling
   OS must keep the CPU busy as much as
    possible by executing a (user) process until it
    must wait for an event, and then switch to
    another process.

   Maximum CPU Utilization obtained with
    multiprogramming.

   Processes alternate between consuming
    CPU cycles (CPU-burst) and performing I/O
    (I/O-Burst)
Alternating Sequence of CPU And I/O Bursts
Histogram of CPU-burst Times
Types of Scheduler
1.   Long-term (job) scheduler
     – admits more jobs when the resource utilization is
       low and blocks the incoming jobs from entering
       ready queue when utilization is high.


2.   Medium-term scheduler (swapper)
     – releases suspended processes from memory by
       swapping it out when the memory becomes over
       committed.
Schedulers (cont.)
3. Short-term (CPU) scheduler (dispatcher) –
   controls the CPU sharing among the “ready”
   processes.
Usually, the next process to execute is selected
  under the following circumstances:
   When a process must wait for an event
   When an event occurs (I/O completion, quantum
    expired)
Scheduling Criteria
    The goal is to optimize the system performance,
     and yet-provide responsive service.
    Criteria used:
    CPU Utilization – the percentage of time that the CPU
     is busy to keep the CPU as busy as possible

CPU Utilization = total process burst time x 100%
                  total CPU execution time
                     of all processes
Scheduling Criteria
    System throughput – number of processes completed
     per time unit.

       Throughtput = number of processes
                  total CPU execution time of all processes

    Turnaround Time – elapsed time from the time the
     process is submitted for execution to the time it is
     completed.

       TAT = end time – arrival time (original)
Scheduling Criteria
4. Waiting time – amount of time a process has been waiting
   in the ready queue.

                    WT = TAT – BT

5. Response Time – amount of time it takes from when a
   process was submitted until the first response is produced,
   not output (for time sharing environment). This is the time
   taken by the system to respond to a user input.
Scheduling Criteria
6. Balanced Utilization – percentage of time
   all resources are utilized
7. Predictability – consistency
8. Fairness – the degree to which all processes
   are given equal opportunity to execute.
   Avoidance of starvation
9. Priorities – give preferential treatment to
   processes with higher priorities.
Note:
   Different algorithms may have different
    properties and may favor one type of criterion
    over the other. So, the design of a scheduler
    usually involves a careful balance of all
    requirements and constraints.
Optimization Criteria
 Max CPU utilization
 Max throughput
 Min turnaround time
 Min waiting time
 Min response time
Scheduling Policies
   Non-preemptive scheduling
     Once the CPU is given to a process it cannot be
     preempted or interrupted until its CPU Burst is
     completed (no suspension)

   Preemptive scheduling
     Force the current executing processes to release
     the CPU on certain events such as clock interrupt,
     I/O interrupts or a system call. (with suspension).
Common Scheduling Algorithms


 Non-Preemptive               Preemptive


       FCFS                      RR

 Both Preemptive and Non-preemptive:
           SJF and Priority
First-Come, First-Ser ved (FCFS)
Scheduling algorithm
 Also known as First in First out (FIFO)
 Simplest scheduling policy
 Arriving jobs are inserted into the tail of the
  ready queue and the process to execute next
  is removed from the head of the queue.
 Jobs are scheduled in the order in which they
  are received.
FCFS Scheduling algorithm
               Process                   Burst Time
                   P1                            24
                   P2                             3
                   P3                      3

   Suppose that the processes arrive in the order: P1 , P2 ,
    P3 . The gantt chart for the schedule is:
                      P1                 P2        P3


           0                        24        27        30


   Waiting time for:      P1 = 0; P2 = 24; P3 = 27
   Average waiting time: (0 + 24 + 27)/3 = 17
FCFS Scheduling (Cont.)
Suppose that the processes arrive in the order
     P2 , P3 , P1
 The Gantt chart for the schedule is:

            P2       P3          P1


        0        3        6                   30


   Waiting time for P1 = 6; P2 = 0; P3 = 3
   Average waiting time: (6 + 0 + 3)/3 = 3
   Much better than previous case
Note
   A long CPU-bound job may hog the CPU and
    may force shorter jobs to wait prolonged
    periods. This may lead to a lengthy queue of
    ready jobs (convoy effect)
Examples:
1. Suppose that the following processes arrive for
   execution, what is the CPU Utilization,
   throughput and average TAT and WT for these
   processes with the FCFS scheduling algorithm

 a) Process BT                  b)   Process    BT
     A      24                       P1        4
     B      10                        P2       1
     C       3                        P3       8
Examples:
2. Calculate the TAT and WT of each process.
   Consider the process arrival and burst times of
   these processes as shown below.

  Process   BT     AT      Process   BT    AT

    A       10     0        P1       8     0.0
    B       5      12       P2       4     0.4
    C       2      13       P3       3     8.2
    D       1      18       P4       2    14.6
    E       5      20       P5       1    16.0
Seatwork
   Calculate the CPU        Process   AT   BT
    Utilization, average       J1      13   4
    TAT and WT for the         J2      5    6
    execution of the
                               J3      3    6
    process below.
    Consider their arrival     J4      24   10
    times and their burst      J5      15   7
    times                      J6      18   7
                               J7      14   8
Process’ CPU and I/O requests
                  CPU and I/O requests
                   use any of the CPU
                   scheduling algorithm.

                  After CPU burst, the I/O
                   burst follows.

                  CPU burst will always be
                   the LAST to perform for
                   the completion of the
                   execution.
Sample problem using CPU and I/O
   With jobs in the ready queue and I/O queue all
    scheduled using FCFS, show the Gantt chart
    showing the execution of these processes.

        Job ID   AT    CPU      I/O    CPU

         P1      0     10       12      5
         P2      3      5        7      4
         P3      10     7       10      2
Shor test-Job-First
Scheduling
   Selects job with the shortest (expected) burst
    time first. Shorter jobs are always executed
    before long jobs

   One major difficulty with SJF is the need to
    know or estimate the burst time of each job
Shortest-Job-First Scheduling
   Another difficulty is long running times may
    starve because the CPU has a steady supply
    of short jobs

   But SJF is optimal – gives minimum WT for a
    given set of processes.

   Preemptive SJF is also known as Shortest
    Remaining Time First (SRTF)
Two schemes:
   Non-Preemptive – once the CPU has given to
    the process it cannot be preempted until it
    completes its CPU burst

   Preemptive – if a new process arrives with
    CPU burst less than the remaining time of
    current executing process, preempt.

     Also known as the Shortest-Remaining-Time-First
     (SRTF)
Example of Non-Preemptive SJF
    Process Arrival Time Burst Time
       P1       0            7
        P2      2            4
        P3      4            1
        P4      5            4
   SJF (non-preemptive)
              P1             P3       P2        P4


       0       3         7        8        12        16


   Average waiting time = (0 + 6 + 3 + 7)/4 = 4
Example of Preemptive SJF (SRTF)

      Process       Arrival Time Burst Time
        P1                  0        7
        P2                  2        4
        P3                  4        1
        P4                  5        4
   SJF (preemptive)
           P1       P2       P3       P2       P4        P1

       0        2        4        5        7        11        16



   Average waiting time = (9 + 1 + 0 +2)/4 = 3
Your turn
   Obtain the average waiting time and the
    turnaround time, including CPU Utilization and
    Gantt Chart for the following set of processes
    using Non-P SJF, and SRTF

    Process   BT     AT     Process   BT     AT
      A       10     0        J1      6      11
      B       6      5        J2      8       0
      C       7      7        J3      12      4
      D       3      6        J4      2       2
      E       1      3        J5      5       5
CPU and I/O request
   With jobs in the ready queue scheduled as SRTF and
    the jobs in the I/O queue scheduled as FCFS, show
    the Gantt chart showing the execution of these
    processes. What is the CPU and I/O utilization?


       Job ID    AT    CPU       I/O    CPU

        P1       0     10        12       5
        P2       3      5         7       4
        P3       10     7        10       2
Priority Scheduling Algorithm (PSA)
 Priority  number (integer) is associated with
  each process
 CPU is allocated to the process with the
  highest priority (smallest integer ≡ highest
  priority)
   Preemptive
   Non-Preemptive
PSA
 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
Sample Problem #1:
Process       BT       PL (HP = 1)
    P1                 8    4
    P2                 1    3
    P3                 3    2
    P4                 4    1
              P4         P3   P2     P1

                                          1
          0   2    4    5     7 8         6
     Average WT: ( 8+7+4+0 ) / 4 = 4.75
     Average TAT: (16+8+7+4 ) / 4 = 8.75
Sample Problem #2:
  Process   BT    PL           AT     (HPL =1)
      P1    8     4            0
      P2    1     3            3
      P3    3     2            5
      P4    4     1            7


Non-Preemptive PSA:       P1                                  P4        P3        P2

                      0                              8        11 12           15 16


Preemptive PSA:                 P2 P        P3                     P3
                          P1        1                    P4                  P1

                      0         3 4     5        7             11 12               16
Round Robin (RR) Scheduling
   Process gets a small unit of CPU time (time
    quantum), usually 10-100 milliseconds. 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.
Round Robin (RR)
 Performance
   q large ⇒ FIFO
   q small ⇒ q must be large with respect to
    context switch, otherwise overhead is too high
Time quantum and context switches
Sample Problem:
                         Process            Burst Time
                            P1                 53
                            P2                 17
                            P3                 68
                            P4                 24



    P1        P2        P3        P4        P1        P3     P4         P1         P3         P3
0        20        37        57        77        97    117        121        134        154        162
Your turn:
 Given the following    Job   AT   BT    PL
  jobs, schedule using                   HPL=1

  PPSA and RR            1     0    18    3
  (QT=4).                2     8    8     2
 Answer the queries     3     10   5     2
  on the next slide.     4     17   12    1
                         5     25   8     3
                         6     30   6     1
Using PPSA, answer the following:
  1. What job is currently allocated to the CPU @
       time 18?
  2.   How many jobs are finished at time 24?
  3.   What is the last job to finish?
  4.   When did job 2 start executing?
  5.   When did job 4 start executing?
  6.   After job 2 totally finished, which job was
       allocated to the CPU?
  7.   What is the waiting time of job 5?
  8.   What is the finish time of job 6?
Using RR, answer the following:
 1. When was job 2 first assigned to the CPU?
 2. How many jobs are finished at time 22?
 3. Which job was allocated the CPU at time 19?
 4. Which job was allocated the CPU at time 29?
 5. After job 3 was totally finished, which job was
    allocated to the CPU?
 6. What is the finish time of job 3?
 7. What is the last job to finish?
 8. What is the turnaround time of job 1?
Comparison between PPSA and RR:
   Comparing the 2 algorithms:
    1. Which algorithm did job 2 start the earliest?
    2. Which algorithm did job 5 start the latest?
    3. Which algorithm did job 1 finish the earliest?
    4. Which algorithm did job 1 finish the latest?
Multilevel Queue
 Ready   queue is partitioned into separate
  queues:
  foreground (interactive) & background
  (batch)
 Each queue has its own scheduling
  algorithm
   foreground – RR
   background – FCFS
 Serves  foreground first then background
  Possibility of starvation.
Multilevel Queue Scheduling
MLQ Example
                                Job   AT   BT   Type
   Assume that the CPU
                                 1    0    5     B
    scheduler uses MLQ
    with 2 levels: foreground    2    7    20    B
    queue for type F (jobs       3    8    1     F
    uses SJF); and               4    9    12    F
    background queue for         5    50   10    B
    type B (jobs uses FCFS).
                                 6    75   15    B
     Scheduling algorithms
    between queues is fixed      7    76   2     F
    preemptive priority ( F      8    78   2     F
    being the highest
    priority)
Activity
Assuming the ready queue is partitioned into
  2 queues: Background queue - processes
  with priorities from 3-5 (uses FCFS); and    J   BT AT P
  Foreground - processes with priorities 1
  and 2. (uses RR with Q=6. Algorithm          A   12 17    1
  between queues is preemptive priority.
  Draw the Gantt chart for the CPU.            B   15 18    4
                                               C   7    1   2
                                               D   11 20    2
                                               E   4    5   3
                                               F   24   0   5
Multilevel Feedback Queue
   A process can move between the various
    queues; aging can be implemented this way
   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
Example of Multilevel Feedback Queue
   Three queues:
     Q0 – RR with time quantum 8 milliseconds
     Q1 – RR time quantum 16 milliseconds
     Q2 – FCFS
Multilevel Feedback Queue: Scheduling




   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.
MLFQ Example
   Schedule using an
                        Job   BT   AT
    MLFQ:
                        A     10   4
    Q1: RR Q=3          B     13   3
    Q2: RR Q=5
                        C     5    0
    Q3: FCFS
                        D     6    1

                        E     18   1
Try it!
                         Job   BT   AT
    Schedule using an
     MLFQ:               A     24   32

                         B     36   15
     Q1: RR with Q=4
     Q2: RR with Q=10    C     17   0

     Q3: FCFS            D     9    1

                         E     15   17
Solaris 2 Scheduling
Solaris Dispatch Table
Windows XP Priorities

More Related Content

What's hot

Sorting Algorithm
Sorting AlgorithmSorting Algorithm
Sorting AlgorithmAl Amin
 
Operating Systems: Process Scheduling
Operating Systems: Process SchedulingOperating Systems: Process Scheduling
Operating Systems: Process SchedulingDamian T. Gordon
 
how to calclute time complexity of algortihm
how to calclute time complexity of algortihmhow to calclute time complexity of algortihm
how to calclute time complexity of algortihmSajid Marwat
 
Cpu scheduling in operating System.
Cpu scheduling in operating System.Cpu scheduling in operating System.
Cpu scheduling in operating System.Ravi Kumar Patel
 
CPU Scheduling algorithms
CPU Scheduling algorithmsCPU Scheduling algorithms
CPU Scheduling algorithmsShanu Kumar
 
Binary search in data structure
Binary search in data structureBinary search in data structure
Binary search in data structureMeherul1234
 
First-Come-First-Serve (FCFS)
First-Come-First-Serve (FCFS)First-Come-First-Serve (FCFS)
First-Come-First-Serve (FCFS)nikeAthena
 
Skip list vinay khimsuriya_200430723005
Skip list vinay khimsuriya_200430723005Skip list vinay khimsuriya_200430723005
Skip list vinay khimsuriya_200430723005vinaykhimsuriya1
 
HES2011 - Tarjei Mandt – Kernel Pool Exploitation on Windows 7
HES2011 - Tarjei Mandt – Kernel Pool Exploitation on Windows 7HES2011 - Tarjei Mandt – Kernel Pool Exploitation on Windows 7
HES2011 - Tarjei Mandt – Kernel Pool Exploitation on Windows 7Hackito Ergo Sum
 
Apache Flink: API, runtime, and project roadmap
Apache Flink: API, runtime, and project roadmapApache Flink: API, runtime, and project roadmap
Apache Flink: API, runtime, and project roadmapKostas Tzoumas
 
CS304PC:Computer Organization and Architecture UNIT I.pdf
CS304PC:Computer Organization and Architecture UNIT I.pdfCS304PC:Computer Organization and Architecture UNIT I.pdf
CS304PC:Computer Organization and Architecture UNIT I.pdfAsst.prof M.Gokilavani
 
Shortest job first Scheduling (SJF)
Shortest job first Scheduling (SJF)Shortest job first Scheduling (SJF)
Shortest job first Scheduling (SJF)ritu98
 
EE5440 – Computer Architecture - Lecture 1
EE5440 – Computer Architecture - Lecture 1EE5440 – Computer Architecture - Lecture 1
EE5440 – Computer Architecture - Lecture 1Dilawar Khan
 
First Come First Serve
First Come First ServeFirst Come First Serve
First Come First ServeEdwin Makeu
 
【学習メモ#7th】12ステップで作る組込みOS自作入門
【学習メモ#7th】12ステップで作る組込みOS自作入門 【学習メモ#7th】12ステップで作る組込みOS自作入門
【学習メモ#7th】12ステップで作る組込みOS自作入門 sandai
 
Lecture 10 data structures and algorithms
Lecture 10 data structures and algorithmsLecture 10 data structures and algorithms
Lecture 10 data structures and algorithmsAakash deep Singhal
 
CPU scheduling algorithms in OS
CPU scheduling algorithms in OSCPU scheduling algorithms in OS
CPU scheduling algorithms in OSharini0810
 

What's hot (20)

Sorting Algorithm
Sorting AlgorithmSorting Algorithm
Sorting Algorithm
 
Operating Systems: Process Scheduling
Operating Systems: Process SchedulingOperating Systems: Process Scheduling
Operating Systems: Process Scheduling
 
how to calclute time complexity of algortihm
how to calclute time complexity of algortihmhow to calclute time complexity of algortihm
how to calclute time complexity of algortihm
 
Cpu scheduling in operating System.
Cpu scheduling in operating System.Cpu scheduling in operating System.
Cpu scheduling in operating System.
 
CPU Scheduling algorithms
CPU Scheduling algorithmsCPU Scheduling algorithms
CPU Scheduling algorithms
 
Binary search in data structure
Binary search in data structureBinary search in data structure
Binary search in data structure
 
First-Come-First-Serve (FCFS)
First-Come-First-Serve (FCFS)First-Come-First-Serve (FCFS)
First-Come-First-Serve (FCFS)
 
Skip list vinay khimsuriya_200430723005
Skip list vinay khimsuriya_200430723005Skip list vinay khimsuriya_200430723005
Skip list vinay khimsuriya_200430723005
 
HES2011 - Tarjei Mandt – Kernel Pool Exploitation on Windows 7
HES2011 - Tarjei Mandt – Kernel Pool Exploitation on Windows 7HES2011 - Tarjei Mandt – Kernel Pool Exploitation on Windows 7
HES2011 - Tarjei Mandt – Kernel Pool Exploitation on Windows 7
 
First Come First Serve (FCFS).pptx
First Come First Serve (FCFS).pptxFirst Come First Serve (FCFS).pptx
First Come First Serve (FCFS).pptx
 
Apache Flink: API, runtime, and project roadmap
Apache Flink: API, runtime, and project roadmapApache Flink: API, runtime, and project roadmap
Apache Flink: API, runtime, and project roadmap
 
CS304PC:Computer Organization and Architecture UNIT I.pdf
CS304PC:Computer Organization and Architecture UNIT I.pdfCS304PC:Computer Organization and Architecture UNIT I.pdf
CS304PC:Computer Organization and Architecture UNIT I.pdf
 
Shortest job first Scheduling (SJF)
Shortest job first Scheduling (SJF)Shortest job first Scheduling (SJF)
Shortest job first Scheduling (SJF)
 
EE5440 – Computer Architecture - Lecture 1
EE5440 – Computer Architecture - Lecture 1EE5440 – Computer Architecture - Lecture 1
EE5440 – Computer Architecture - Lecture 1
 
First Come First Serve
First Come First ServeFirst Come First Serve
First Come First Serve
 
VIRTUAL MEMORY
VIRTUAL MEMORYVIRTUAL MEMORY
VIRTUAL MEMORY
 
【学習メモ#7th】12ステップで作る組込みOS自作入門
【学習メモ#7th】12ステップで作る組込みOS自作入門 【学習メモ#7th】12ステップで作る組込みOS自作入門
【学習メモ#7th】12ステップで作る組込みOS自作入門
 
Lecture 10 data structures and algorithms
Lecture 10 data structures and algorithmsLecture 10 data structures and algorithms
Lecture 10 data structures and algorithms
 
CPU Scheduling Algorithms
CPU Scheduling AlgorithmsCPU Scheduling Algorithms
CPU Scheduling Algorithms
 
CPU scheduling algorithms in OS
CPU scheduling algorithms in OSCPU scheduling algorithms in OS
CPU scheduling algorithms in OS
 

Viewers also liked

Srt division (2)
Srt division (2)Srt division (2)
Srt division (2)miladce
 
Processor / CPU Scheduling
Processor / CPU SchedulingProcessor / CPU Scheduling
Processor / CPU SchedulingIzaz Roghani
 
Detoxification
DetoxificationDetoxification
Detoxificationguest38a88
 
Gunas quiz
Gunas quizGunas quiz
Gunas quizdividisa
 
4838281 operating-system-scheduling-on-multicore-architectures
4838281 operating-system-scheduling-on-multicore-architectures4838281 operating-system-scheduling-on-multicore-architectures
4838281 operating-system-scheduling-on-multicore-architecturesIslam Samir
 
Eating for Balance, The Six Tastes of Ayurveda and What to Eat for Your Dosha
Eating for Balance, The Six Tastes of Ayurveda and What to Eat for Your DoshaEating for Balance, The Six Tastes of Ayurveda and What to Eat for Your Dosha
Eating for Balance, The Six Tastes of Ayurveda and What to Eat for Your DoshaPamela Quinn
 
Management of Common Disorders - 120412
Management of Common Disorders - 120412Management of Common Disorders - 120412
Management of Common Disorders - 120412Dhananjay Arankalle
 
06 The Three Temperaments Edited
06 The Three Temperaments Edited06 The Three Temperaments Edited
06 The Three Temperaments EditedYatin Mota
 
Real time Scheduling in Operating System for Msc CS
Real time Scheduling in Operating System for Msc CSReal time Scheduling in Operating System for Msc CS
Real time Scheduling in Operating System for Msc CSThanveen
 

Viewers also liked (16)

Srt division (2)
Srt division (2)Srt division (2)
Srt division (2)
 
Sa by shekhar
Sa by shekharSa by shekhar
Sa by shekhar
 
Cp usched 2
Cp usched  2Cp usched  2
Cp usched 2
 
Processor / CPU Scheduling
Processor / CPU SchedulingProcessor / CPU Scheduling
Processor / CPU Scheduling
 
Detoxification
DetoxificationDetoxification
Detoxification
 
Gunas quiz
Gunas quizGunas quiz
Gunas quiz
 
4838281 operating-system-scheduling-on-multicore-architectures
4838281 operating-system-scheduling-on-multicore-architectures4838281 operating-system-scheduling-on-multicore-architectures
4838281 operating-system-scheduling-on-multicore-architectures
 
Eating for Balance, The Six Tastes of Ayurveda and What to Eat for Your Dosha
Eating for Balance, The Six Tastes of Ayurveda and What to Eat for Your DoshaEating for Balance, The Six Tastes of Ayurveda and What to Eat for Your Dosha
Eating for Balance, The Six Tastes of Ayurveda and What to Eat for Your Dosha
 
Management of Common Disorders - 120412
Management of Common Disorders - 120412Management of Common Disorders - 120412
Management of Common Disorders - 120412
 
Tri guna
Tri gunaTri guna
Tri guna
 
06 The Three Temperaments Edited
06 The Three Temperaments Edited06 The Three Temperaments Edited
06 The Three Temperaments Edited
 
VARNA DHARMA
VARNA DHARMAVARNA DHARMA
VARNA DHARMA
 
Real time Scheduling in Operating System for Msc CS
Real time Scheduling in Operating System for Msc CSReal time Scheduling in Operating System for Msc CS
Real time Scheduling in Operating System for Msc CS
 
Cpu Scheduling Galvin
Cpu Scheduling GalvinCpu Scheduling Galvin
Cpu Scheduling Galvin
 
5 Process Scheduling
5 Process Scheduling5 Process Scheduling
5 Process Scheduling
 
Chapter6
Chapter6Chapter6
Chapter6
 

Similar to Os module 2 ba

Similar to Os module 2 ba (20)

CPU Scheduling
CPU SchedulingCPU Scheduling
CPU Scheduling
 
Process management in os
Process management in osProcess management in os
Process management in os
 
CPU scheduling
CPU schedulingCPU scheduling
CPU scheduling
 
Preemptive process example.pptx
Preemptive process example.pptxPreemptive process example.pptx
Preemptive process example.pptx
 
Operating Systems Third Unit - Fourth Semester - Engineering
Operating Systems Third Unit  - Fourth Semester - EngineeringOperating Systems Third Unit  - Fourth Semester - Engineering
Operating Systems Third Unit - Fourth Semester - Engineering
 
cpu schduling ppt.pdf
cpu schduling ppt.pdfcpu schduling ppt.pdf
cpu schduling ppt.pdf
 
OSCh6
OSCh6OSCh6
OSCh6
 
OS_Ch6
OS_Ch6OS_Ch6
OS_Ch6
 
CPU Scheduling
CPU SchedulingCPU Scheduling
CPU Scheduling
 
Ch5
Ch5Ch5
Ch5
 
Ch05
Ch05Ch05
Ch05
 
cpu sechduling
cpu sechduling cpu sechduling
cpu sechduling
 
Fcfs and sjf
Fcfs and sjfFcfs and sjf
Fcfs and sjf
 
OS Process Chapter 3.pdf
OS Process Chapter 3.pdfOS Process Chapter 3.pdf
OS Process Chapter 3.pdf
 
Scheduling algo(by HJ)
Scheduling algo(by HJ)Scheduling algo(by HJ)
Scheduling algo(by HJ)
 
CPU Scheduling
CPU SchedulingCPU Scheduling
CPU Scheduling
 
Ch6
Ch6Ch6
Ch6
 
Scheduling algorithm (chammu)
Scheduling algorithm (chammu)Scheduling algorithm (chammu)
Scheduling algorithm (chammu)
 
Process Scheduling Algorithms.pdf
Process Scheduling Algorithms.pdfProcess Scheduling Algorithms.pdf
Process Scheduling Algorithms.pdf
 
CH06.pdf
CH06.pdfCH06.pdf
CH06.pdf
 

More from Gichelle Amon (20)

Kerberos
KerberosKerberos
Kerberos
 
Network security
Network securityNetwork security
Network security
 
Os module 2 d
Os module 2 dOs module 2 d
Os module 2 d
 
Os module 2 c
Os module 2 cOs module 2 c
Os module 2 c
 
Image segmentation ppt
Image segmentation pptImage segmentation ppt
Image segmentation ppt
 
Lec3 final
Lec3 finalLec3 final
Lec3 final
 
Lec 3
Lec 3Lec 3
Lec 3
 
Lec2 final
Lec2 finalLec2 final
Lec2 final
 
Lec 4
Lec 4Lec 4
Lec 4
 
Lec1 final
Lec1 finalLec1 final
Lec1 final
 
Module 3 law of contracts
Module 3  law of contractsModule 3  law of contracts
Module 3 law of contracts
 
Transport triggered architecture
Transport triggered architectureTransport triggered architecture
Transport triggered architecture
 
Time triggered arch.
Time triggered arch.Time triggered arch.
Time triggered arch.
 
Subnetting
SubnettingSubnetting
Subnetting
 
Os module 2 c
Os module 2 cOs module 2 c
Os module 2 c
 
Lec5
Lec5Lec5
Lec5
 
Delivery
DeliveryDelivery
Delivery
 
Addressing
AddressingAddressing
Addressing
 
6 spatial filtering p2
6 spatial filtering p26 spatial filtering p2
6 spatial filtering p2
 
5 spatial filtering p1
5 spatial filtering p15 spatial filtering p1
5 spatial filtering p1
 

Recently uploaded

VIP Call Girl Jamshedpur Aashi 8250192130 Independent Escort Service Jamshedpur
VIP Call Girl Jamshedpur Aashi 8250192130 Independent Escort Service JamshedpurVIP Call Girl Jamshedpur Aashi 8250192130 Independent Escort Service Jamshedpur
VIP Call Girl Jamshedpur Aashi 8250192130 Independent Escort Service JamshedpurSuhani Kapoor
 
BEST ✨ Call Girls In Indirapuram Ghaziabad ✔️ 9871031762 ✔️ Escorts Service...
BEST ✨ Call Girls In  Indirapuram Ghaziabad  ✔️ 9871031762 ✔️ Escorts Service...BEST ✨ Call Girls In  Indirapuram Ghaziabad  ✔️ 9871031762 ✔️ Escorts Service...
BEST ✨ Call Girls In Indirapuram Ghaziabad ✔️ 9871031762 ✔️ Escorts Service...noida100girls
 
Regression analysis: Simple Linear Regression Multiple Linear Regression
Regression analysis:  Simple Linear Regression Multiple Linear RegressionRegression analysis:  Simple Linear Regression Multiple Linear Regression
Regression analysis: Simple Linear Regression Multiple Linear RegressionRavindra Nath Shukla
 
Ensure the security of your HCL environment by applying the Zero Trust princi...
Ensure the security of your HCL environment by applying the Zero Trust princi...Ensure the security of your HCL environment by applying the Zero Trust princi...
Ensure the security of your HCL environment by applying the Zero Trust princi...Roland Driesen
 
Cash Payment 9602870969 Escort Service in Udaipur Call Girls
Cash Payment 9602870969 Escort Service in Udaipur Call GirlsCash Payment 9602870969 Escort Service in Udaipur Call Girls
Cash Payment 9602870969 Escort Service in Udaipur Call GirlsApsara Of India
 
Eni 2024 1Q Results - 24.04.24 business.
Eni 2024 1Q Results - 24.04.24 business.Eni 2024 1Q Results - 24.04.24 business.
Eni 2024 1Q Results - 24.04.24 business.Eni
 
Tech Startup Growth Hacking 101 - Basics on Growth Marketing
Tech Startup Growth Hacking 101  - Basics on Growth MarketingTech Startup Growth Hacking 101  - Basics on Growth Marketing
Tech Startup Growth Hacking 101 - Basics on Growth MarketingShawn Pang
 
0183760ssssssssssssssssssssssssssss00101011 (27).pdf
0183760ssssssssssssssssssssssssssss00101011 (27).pdf0183760ssssssssssssssssssssssssssss00101011 (27).pdf
0183760ssssssssssssssssssssssssssss00101011 (27).pdfRenandantas16
 
Keppel Ltd. 1Q 2024 Business Update Presentation Slides
Keppel Ltd. 1Q 2024 Business Update  Presentation SlidesKeppel Ltd. 1Q 2024 Business Update  Presentation Slides
Keppel Ltd. 1Q 2024 Business Update Presentation SlidesKeppelCorporation
 
Grateful 7 speech thanking everyone that has helped.pdf
Grateful 7 speech thanking everyone that has helped.pdfGrateful 7 speech thanking everyone that has helped.pdf
Grateful 7 speech thanking everyone that has helped.pdfPaul Menig
 
MONA 98765-12871 CALL GIRLS IN LUDHIANA LUDHIANA CALL GIRL
MONA 98765-12871 CALL GIRLS IN LUDHIANA LUDHIANA CALL GIRLMONA 98765-12871 CALL GIRLS IN LUDHIANA LUDHIANA CALL GIRL
MONA 98765-12871 CALL GIRLS IN LUDHIANA LUDHIANA CALL GIRLSeo
 
Pharma Works Profile of Karan Communications
Pharma Works Profile of Karan CommunicationsPharma Works Profile of Karan Communications
Pharma Works Profile of Karan Communicationskarancommunications
 
VIP Call Girls In Saharaganj ( Lucknow ) 🔝 8923113531 🔝 Cash Payment (COD) 👒
VIP Call Girls In Saharaganj ( Lucknow  ) 🔝 8923113531 🔝  Cash Payment (COD) 👒VIP Call Girls In Saharaganj ( Lucknow  ) 🔝 8923113531 🔝  Cash Payment (COD) 👒
VIP Call Girls In Saharaganj ( Lucknow ) 🔝 8923113531 🔝 Cash Payment (COD) 👒anilsa9823
 
Best VIP Call Girls Noida Sector 40 Call Me: 8448380779
Best VIP Call Girls Noida Sector 40 Call Me: 8448380779Best VIP Call Girls Noida Sector 40 Call Me: 8448380779
Best VIP Call Girls Noida Sector 40 Call Me: 8448380779Delhi Call girls
 
Insurers' journeys to build a mastery in the IoT usage
Insurers' journeys to build a mastery in the IoT usageInsurers' journeys to build a mastery in the IoT usage
Insurers' journeys to build a mastery in the IoT usageMatteo Carbone
 
VIP Kolkata Call Girl Howrah 👉 8250192130 Available With Room
VIP Kolkata Call Girl Howrah 👉 8250192130  Available With RoomVIP Kolkata Call Girl Howrah 👉 8250192130  Available With Room
VIP Kolkata Call Girl Howrah 👉 8250192130 Available With Roomdivyansh0kumar0
 
Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...
Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...
Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...Dave Litwiller
 
Mondelez State of Snacking and Future Trends 2023
Mondelez State of Snacking and Future Trends 2023Mondelez State of Snacking and Future Trends 2023
Mondelez State of Snacking and Future Trends 2023Neil Kimberley
 
Catalogue ONG NƯỚC uPVC - HDPE DE NHAT.pdf
Catalogue ONG NƯỚC uPVC - HDPE DE NHAT.pdfCatalogue ONG NƯỚC uPVC - HDPE DE NHAT.pdf
Catalogue ONG NƯỚC uPVC - HDPE DE NHAT.pdfOrient Homes
 

Recently uploaded (20)

VIP Call Girl Jamshedpur Aashi 8250192130 Independent Escort Service Jamshedpur
VIP Call Girl Jamshedpur Aashi 8250192130 Independent Escort Service JamshedpurVIP Call Girl Jamshedpur Aashi 8250192130 Independent Escort Service Jamshedpur
VIP Call Girl Jamshedpur Aashi 8250192130 Independent Escort Service Jamshedpur
 
BEST ✨ Call Girls In Indirapuram Ghaziabad ✔️ 9871031762 ✔️ Escorts Service...
BEST ✨ Call Girls In  Indirapuram Ghaziabad  ✔️ 9871031762 ✔️ Escorts Service...BEST ✨ Call Girls In  Indirapuram Ghaziabad  ✔️ 9871031762 ✔️ Escorts Service...
BEST ✨ Call Girls In Indirapuram Ghaziabad ✔️ 9871031762 ✔️ Escorts Service...
 
Regression analysis: Simple Linear Regression Multiple Linear Regression
Regression analysis:  Simple Linear Regression Multiple Linear RegressionRegression analysis:  Simple Linear Regression Multiple Linear Regression
Regression analysis: Simple Linear Regression Multiple Linear Regression
 
Nepali Escort Girl Kakori \ 9548273370 Indian Call Girls Service Lucknow ₹,9517
Nepali Escort Girl Kakori \ 9548273370 Indian Call Girls Service Lucknow ₹,9517Nepali Escort Girl Kakori \ 9548273370 Indian Call Girls Service Lucknow ₹,9517
Nepali Escort Girl Kakori \ 9548273370 Indian Call Girls Service Lucknow ₹,9517
 
Ensure the security of your HCL environment by applying the Zero Trust princi...
Ensure the security of your HCL environment by applying the Zero Trust princi...Ensure the security of your HCL environment by applying the Zero Trust princi...
Ensure the security of your HCL environment by applying the Zero Trust princi...
 
Cash Payment 9602870969 Escort Service in Udaipur Call Girls
Cash Payment 9602870969 Escort Service in Udaipur Call GirlsCash Payment 9602870969 Escort Service in Udaipur Call Girls
Cash Payment 9602870969 Escort Service in Udaipur Call Girls
 
Eni 2024 1Q Results - 24.04.24 business.
Eni 2024 1Q Results - 24.04.24 business.Eni 2024 1Q Results - 24.04.24 business.
Eni 2024 1Q Results - 24.04.24 business.
 
Tech Startup Growth Hacking 101 - Basics on Growth Marketing
Tech Startup Growth Hacking 101  - Basics on Growth MarketingTech Startup Growth Hacking 101  - Basics on Growth Marketing
Tech Startup Growth Hacking 101 - Basics on Growth Marketing
 
0183760ssssssssssssssssssssssssssss00101011 (27).pdf
0183760ssssssssssssssssssssssssssss00101011 (27).pdf0183760ssssssssssssssssssssssssssss00101011 (27).pdf
0183760ssssssssssssssssssssssssssss00101011 (27).pdf
 
Keppel Ltd. 1Q 2024 Business Update Presentation Slides
Keppel Ltd. 1Q 2024 Business Update  Presentation SlidesKeppel Ltd. 1Q 2024 Business Update  Presentation Slides
Keppel Ltd. 1Q 2024 Business Update Presentation Slides
 
Grateful 7 speech thanking everyone that has helped.pdf
Grateful 7 speech thanking everyone that has helped.pdfGrateful 7 speech thanking everyone that has helped.pdf
Grateful 7 speech thanking everyone that has helped.pdf
 
MONA 98765-12871 CALL GIRLS IN LUDHIANA LUDHIANA CALL GIRL
MONA 98765-12871 CALL GIRLS IN LUDHIANA LUDHIANA CALL GIRLMONA 98765-12871 CALL GIRLS IN LUDHIANA LUDHIANA CALL GIRL
MONA 98765-12871 CALL GIRLS IN LUDHIANA LUDHIANA CALL GIRL
 
Pharma Works Profile of Karan Communications
Pharma Works Profile of Karan CommunicationsPharma Works Profile of Karan Communications
Pharma Works Profile of Karan Communications
 
VIP Call Girls In Saharaganj ( Lucknow ) 🔝 8923113531 🔝 Cash Payment (COD) 👒
VIP Call Girls In Saharaganj ( Lucknow  ) 🔝 8923113531 🔝  Cash Payment (COD) 👒VIP Call Girls In Saharaganj ( Lucknow  ) 🔝 8923113531 🔝  Cash Payment (COD) 👒
VIP Call Girls In Saharaganj ( Lucknow ) 🔝 8923113531 🔝 Cash Payment (COD) 👒
 
Best VIP Call Girls Noida Sector 40 Call Me: 8448380779
Best VIP Call Girls Noida Sector 40 Call Me: 8448380779Best VIP Call Girls Noida Sector 40 Call Me: 8448380779
Best VIP Call Girls Noida Sector 40 Call Me: 8448380779
 
Insurers' journeys to build a mastery in the IoT usage
Insurers' journeys to build a mastery in the IoT usageInsurers' journeys to build a mastery in the IoT usage
Insurers' journeys to build a mastery in the IoT usage
 
VIP Kolkata Call Girl Howrah 👉 8250192130 Available With Room
VIP Kolkata Call Girl Howrah 👉 8250192130  Available With RoomVIP Kolkata Call Girl Howrah 👉 8250192130  Available With Room
VIP Kolkata Call Girl Howrah 👉 8250192130 Available With Room
 
Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...
Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...
Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...
 
Mondelez State of Snacking and Future Trends 2023
Mondelez State of Snacking and Future Trends 2023Mondelez State of Snacking and Future Trends 2023
Mondelez State of Snacking and Future Trends 2023
 
Catalogue ONG NƯỚC uPVC - HDPE DE NHAT.pdf
Catalogue ONG NƯỚC uPVC - HDPE DE NHAT.pdfCatalogue ONG NƯỚC uPVC - HDPE DE NHAT.pdf
Catalogue ONG NƯỚC uPVC - HDPE DE NHAT.pdf
 

Os module 2 ba

  • 1. The OS as a time keeper
  • 2. Scheduling  In multiprogramming systems, the OS decides which one to activate when there is more than one runnable process (in the ready queue).  The decision is made by the part of the OS called scheduler using a scheduling algorithm.
  • 3. Scheduling  Set of policies and mechanisms to control the order of work to be performed by a computer system.
  • 4. Scheduling  OS must keep the CPU busy as much as possible by executing a (user) process until it must wait for an event, and then switch to another process.  Maximum CPU Utilization obtained with multiprogramming.  Processes alternate between consuming CPU cycles (CPU-burst) and performing I/O (I/O-Burst)
  • 5. Alternating Sequence of CPU And I/O Bursts
  • 7. Types of Scheduler 1. Long-term (job) scheduler – admits more jobs when the resource utilization is low and blocks the incoming jobs from entering ready queue when utilization is high. 2. Medium-term scheduler (swapper) – releases suspended processes from memory by swapping it out when the memory becomes over committed.
  • 8. Schedulers (cont.) 3. Short-term (CPU) scheduler (dispatcher) – controls the CPU sharing among the “ready” processes. Usually, the next process to execute is selected under the following circumstances:  When a process must wait for an event  When an event occurs (I/O completion, quantum expired)
  • 9. Scheduling Criteria  The goal is to optimize the system performance, and yet-provide responsive service.  Criteria used:  CPU Utilization – the percentage of time that the CPU is busy to keep the CPU as busy as possible CPU Utilization = total process burst time x 100% total CPU execution time of all processes
  • 10. Scheduling Criteria  System throughput – number of processes completed per time unit. Throughtput = number of processes total CPU execution time of all processes  Turnaround Time – elapsed time from the time the process is submitted for execution to the time it is completed. TAT = end time – arrival time (original)
  • 11. Scheduling Criteria 4. Waiting time – amount of time a process has been waiting in the ready queue. WT = TAT – BT 5. Response Time – amount of time it takes from when a process was submitted until the first response is produced, not output (for time sharing environment). This is the time taken by the system to respond to a user input.
  • 12. Scheduling Criteria 6. Balanced Utilization – percentage of time all resources are utilized 7. Predictability – consistency 8. Fairness – the degree to which all processes are given equal opportunity to execute. Avoidance of starvation 9. Priorities – give preferential treatment to processes with higher priorities.
  • 13. Note:  Different algorithms may have different properties and may favor one type of criterion over the other. So, the design of a scheduler usually involves a careful balance of all requirements and constraints.
  • 14. Optimization Criteria  Max CPU utilization  Max throughput  Min turnaround time  Min waiting time  Min response time
  • 15. Scheduling Policies  Non-preemptive scheduling  Once the CPU is given to a process it cannot be preempted or interrupted until its CPU Burst is completed (no suspension)  Preemptive scheduling  Force the current executing processes to release the CPU on certain events such as clock interrupt, I/O interrupts or a system call. (with suspension).
  • 16. Common Scheduling Algorithms Non-Preemptive Preemptive FCFS RR Both Preemptive and Non-preemptive: SJF and Priority
  • 17. First-Come, First-Ser ved (FCFS) Scheduling algorithm  Also known as First in First out (FIFO)  Simplest scheduling policy  Arriving jobs are inserted into the tail of the ready queue and the process to execute next is removed from the head of the queue.  Jobs are scheduled in the order in which they are received.
  • 18. FCFS Scheduling algorithm Process Burst Time P1 24 P2 3 P3 3  Suppose that the processes arrive in the order: P1 , P2 , P3 . The gantt chart for the schedule is: P1 P2 P3 0 24 27 30  Waiting time for: P1 = 0; P2 = 24; P3 = 27  Average waiting time: (0 + 24 + 27)/3 = 17
  • 19. FCFS Scheduling (Cont.) Suppose that the processes arrive in the order P2 , P3 , P1  The Gantt chart for the schedule is: P2 P3 P1 0 3 6 30  Waiting time for P1 = 6; P2 = 0; P3 = 3  Average waiting time: (6 + 0 + 3)/3 = 3  Much better than previous case
  • 20. Note  A long CPU-bound job may hog the CPU and may force shorter jobs to wait prolonged periods. This may lead to a lengthy queue of ready jobs (convoy effect)
  • 21. Examples: 1. Suppose that the following processes arrive for execution, what is the CPU Utilization, throughput and average TAT and WT for these processes with the FCFS scheduling algorithm a) Process BT b) Process BT A 24 P1 4 B 10 P2 1 C 3 P3 8
  • 22. Examples: 2. Calculate the TAT and WT of each process. Consider the process arrival and burst times of these processes as shown below. Process BT AT Process BT AT A 10 0 P1 8 0.0 B 5 12 P2 4 0.4 C 2 13 P3 3 8.2 D 1 18 P4 2 14.6 E 5 20 P5 1 16.0
  • 23. Seatwork  Calculate the CPU Process AT BT Utilization, average J1 13 4 TAT and WT for the J2 5 6 execution of the J3 3 6 process below. Consider their arrival J4 24 10 times and their burst J5 15 7 times J6 18 7 J7 14 8
  • 24. Process’ CPU and I/O requests  CPU and I/O requests use any of the CPU scheduling algorithm.  After CPU burst, the I/O burst follows.  CPU burst will always be the LAST to perform for the completion of the execution.
  • 25. Sample problem using CPU and I/O  With jobs in the ready queue and I/O queue all scheduled using FCFS, show the Gantt chart showing the execution of these processes. Job ID AT CPU I/O CPU P1 0 10 12 5 P2 3 5 7 4 P3 10 7 10 2
  • 26. Shor test-Job-First Scheduling  Selects job with the shortest (expected) burst time first. Shorter jobs are always executed before long jobs  One major difficulty with SJF is the need to know or estimate the burst time of each job
  • 27. Shortest-Job-First Scheduling  Another difficulty is long running times may starve because the CPU has a steady supply of short jobs  But SJF is optimal – gives minimum WT for a given set of processes.  Preemptive SJF is also known as Shortest Remaining Time First (SRTF)
  • 28. Two schemes:  Non-Preemptive – once the CPU has given to the process it cannot be preempted until it completes its CPU burst  Preemptive – if a new process arrives with CPU burst less than the remaining time of current executing process, preempt.  Also known as the Shortest-Remaining-Time-First (SRTF)
  • 29. Example of Non-Preemptive SJF Process Arrival Time Burst Time P1 0 7 P2 2 4 P3 4 1 P4 5 4  SJF (non-preemptive) P1 P3 P2 P4 0 3 7 8 12 16  Average waiting time = (0 + 6 + 3 + 7)/4 = 4
  • 30. Example of Preemptive SJF (SRTF) Process Arrival Time Burst Time P1 0 7 P2 2 4 P3 4 1 P4 5 4  SJF (preemptive) P1 P2 P3 P2 P4 P1 0 2 4 5 7 11 16  Average waiting time = (9 + 1 + 0 +2)/4 = 3
  • 31. Your turn  Obtain the average waiting time and the turnaround time, including CPU Utilization and Gantt Chart for the following set of processes using Non-P SJF, and SRTF Process BT AT Process BT AT A 10 0 J1 6 11 B 6 5 J2 8 0 C 7 7 J3 12 4 D 3 6 J4 2 2 E 1 3 J5 5 5
  • 32. CPU and I/O request  With jobs in the ready queue scheduled as SRTF and the jobs in the I/O queue scheduled as FCFS, show the Gantt chart showing the execution of these processes. What is the CPU and I/O utilization? Job ID AT CPU I/O CPU P1 0 10 12 5 P2 3 5 7 4 P3 10 7 10 2
  • 33. Priority Scheduling Algorithm (PSA)  Priority number (integer) is associated with each process  CPU is allocated to the process with the highest priority (smallest integer ≡ highest priority)  Preemptive  Non-Preemptive
  • 34. PSA  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
  • 35. Sample Problem #1: Process BT PL (HP = 1) P1 8 4 P2 1 3 P3 3 2 P4 4 1 P4 P3 P2 P1 1 0 2 4 5 7 8 6 Average WT: ( 8+7+4+0 ) / 4 = 4.75 Average TAT: (16+8+7+4 ) / 4 = 8.75
  • 36. Sample Problem #2: Process BT PL AT (HPL =1) P1 8 4 0 P2 1 3 3 P3 3 2 5 P4 4 1 7 Non-Preemptive PSA: P1 P4 P3 P2 0 8 11 12 15 16 Preemptive PSA: P2 P P3 P3 P1 1 P4 P1 0 3 4 5 7 11 12 16
  • 37. Round Robin (RR) Scheduling  Process gets a small unit of CPU time (time quantum), usually 10-100 milliseconds. 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.
  • 38. Round Robin (RR)  Performance  q large ⇒ FIFO  q small ⇒ q must be large with respect to context switch, otherwise overhead is too high
  • 39. Time quantum and context switches
  • 40. Sample Problem: Process Burst Time P1 53 P2 17 P3 68 P4 24 P1 P2 P3 P4 P1 P3 P4 P1 P3 P3 0 20 37 57 77 97 117 121 134 154 162
  • 41. Your turn:  Given the following Job AT BT PL jobs, schedule using HPL=1 PPSA and RR 1 0 18 3 (QT=4). 2 8 8 2  Answer the queries 3 10 5 2 on the next slide. 4 17 12 1 5 25 8 3 6 30 6 1
  • 42. Using PPSA, answer the following: 1. What job is currently allocated to the CPU @ time 18? 2. How many jobs are finished at time 24? 3. What is the last job to finish? 4. When did job 2 start executing? 5. When did job 4 start executing? 6. After job 2 totally finished, which job was allocated to the CPU? 7. What is the waiting time of job 5? 8. What is the finish time of job 6?
  • 43. Using RR, answer the following: 1. When was job 2 first assigned to the CPU? 2. How many jobs are finished at time 22? 3. Which job was allocated the CPU at time 19? 4. Which job was allocated the CPU at time 29? 5. After job 3 was totally finished, which job was allocated to the CPU? 6. What is the finish time of job 3? 7. What is the last job to finish? 8. What is the turnaround time of job 1?
  • 44. Comparison between PPSA and RR:  Comparing the 2 algorithms: 1. Which algorithm did job 2 start the earliest? 2. Which algorithm did job 5 start the latest? 3. Which algorithm did job 1 finish the earliest? 4. Which algorithm did job 1 finish the latest?
  • 45. Multilevel Queue  Ready queue is partitioned into separate queues: foreground (interactive) & background (batch)  Each queue has its own scheduling algorithm  foreground – RR  background – FCFS  Serves foreground first then background Possibility of starvation.
  • 47. MLQ Example Job AT BT Type  Assume that the CPU 1 0 5 B scheduler uses MLQ with 2 levels: foreground 2 7 20 B queue for type F (jobs 3 8 1 F uses SJF); and 4 9 12 F background queue for 5 50 10 B type B (jobs uses FCFS). 6 75 15 B Scheduling algorithms between queues is fixed 7 76 2 F preemptive priority ( F 8 78 2 F being the highest priority)
  • 48. Activity Assuming the ready queue is partitioned into 2 queues: Background queue - processes with priorities from 3-5 (uses FCFS); and J BT AT P Foreground - processes with priorities 1 and 2. (uses RR with Q=6. Algorithm A 12 17 1 between queues is preemptive priority. Draw the Gantt chart for the CPU. B 15 18 4 C 7 1 2 D 11 20 2 E 4 5 3 F 24 0 5
  • 49. Multilevel Feedback Queue  A process can move between the various queues; aging can be implemented this way  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
  • 50. Example of Multilevel Feedback Queue  Three queues:  Q0 – RR with time quantum 8 milliseconds  Q1 – RR time quantum 16 milliseconds  Q2 – FCFS
  • 51. Multilevel Feedback Queue: Scheduling  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.
  • 52. MLFQ Example  Schedule using an Job BT AT MLFQ: A 10 4 Q1: RR Q=3 B 13 3 Q2: RR Q=5 C 5 0 Q3: FCFS D 6 1 E 18 1
  • 53. Try it! Job BT AT  Schedule using an MLFQ: A 24 32 B 36 15 Q1: RR with Q=4 Q2: RR with Q=10 C 17 0 Q3: FCFS D 9 1 E 15 17