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

Process management in operating system | process states | PCB | FORK() | Zomb...
Process management in operating system | process states | PCB | FORK() | Zomb...Process management in operating system | process states | PCB | FORK() | Zomb...
Process management in operating system | process states | PCB | FORK() | Zomb...Shivam Mitra
 
Real time operating systems (rtos) concepts 4
Real time operating systems (rtos) concepts 4Real time operating systems (rtos) concepts 4
Real time operating systems (rtos) concepts 4Abu Bakr Ramadan
 
OS Process Synchronization, semaphore and Monitors
OS Process Synchronization, semaphore and MonitorsOS Process Synchronization, semaphore and Monitors
OS Process Synchronization, semaphore and Monitorssgpraju
 
Comparison Analysis of CPU Scheduling : FCFS, SJF and Round Robin
Comparison Analysis of CPU Scheduling : FCFS, SJF and Round RobinComparison Analysis of CPU Scheduling : FCFS, SJF and Round Robin
Comparison Analysis of CPU Scheduling : FCFS, SJF and Round RobinUniversitas Pembangunan Panca Budi
 
Real Time Operating Systems
Real Time Operating SystemsReal Time Operating Systems
Real Time Operating SystemsAshwani Garg
 
Operating Systems Process Scheduling Algorithms
Operating Systems   Process Scheduling AlgorithmsOperating Systems   Process Scheduling Algorithms
Operating Systems Process Scheduling Algorithmssathish sak
 
Multilevel queue scheduling
Multilevel queue schedulingMultilevel queue scheduling
Multilevel queue schedulingAditiPawaskar5
 
Address Binding Scheme
Address Binding SchemeAddress Binding Scheme
Address Binding SchemeRajesh Piryani
 
Operating Systems: Process Scheduling
Operating Systems: Process SchedulingOperating Systems: Process Scheduling
Operating Systems: Process SchedulingDamian T. Gordon
 
Fundamentals of Computers
Fundamentals of ComputersFundamentals of Computers
Fundamentals of ComputersAnkur Kumar
 
Concurrent transactions
Concurrent transactionsConcurrent transactions
Concurrent transactionsSajan Sahu
 
management of distributed transactions
management of distributed transactionsmanagement of distributed transactions
management of distributed transactionsNilu Desai
 
Ch9: Memory Management
Ch9: Memory ManagementCh9: Memory Management
Ch9: Memory ManagementAhmar Hashmi
 

What's hot (20)

Batch operating system
Batch operating system Batch operating system
Batch operating system
 
Process management in operating system | process states | PCB | FORK() | Zomb...
Process management in operating system | process states | PCB | FORK() | Zomb...Process management in operating system | process states | PCB | FORK() | Zomb...
Process management in operating system | process states | PCB | FORK() | Zomb...
 
Introduction to parallel computing
Introduction to parallel computingIntroduction to parallel computing
Introduction to parallel computing
 
Real time operating systems (rtos) concepts 4
Real time operating systems (rtos) concepts 4Real time operating systems (rtos) concepts 4
Real time operating systems (rtos) concepts 4
 
OS Process Synchronization, semaphore and Monitors
OS Process Synchronization, semaphore and MonitorsOS Process Synchronization, semaphore and Monitors
OS Process Synchronization, semaphore and Monitors
 
Comparison Analysis of CPU Scheduling : FCFS, SJF and Round Robin
Comparison Analysis of CPU Scheduling : FCFS, SJF and Round RobinComparison Analysis of CPU Scheduling : FCFS, SJF and Round Robin
Comparison Analysis of CPU Scheduling : FCFS, SJF and Round Robin
 
Real Time Operating Systems
Real Time Operating SystemsReal Time Operating Systems
Real Time Operating Systems
 
Operating Systems Process Scheduling Algorithms
Operating Systems   Process Scheduling AlgorithmsOperating Systems   Process Scheduling Algorithms
Operating Systems Process Scheduling Algorithms
 
Multilevel queue scheduling
Multilevel queue schedulingMultilevel queue scheduling
Multilevel queue scheduling
 
Address Binding Scheme
Address Binding SchemeAddress Binding Scheme
Address Binding Scheme
 
Notes on NUMA architecture
Notes on NUMA architectureNotes on NUMA architecture
Notes on NUMA architecture
 
Parallel Algorithms
Parallel AlgorithmsParallel Algorithms
Parallel Algorithms
 
Ch4 memory management
Ch4 memory managementCh4 memory management
Ch4 memory management
 
Operating Systems: Process Scheduling
Operating Systems: Process SchedulingOperating Systems: Process Scheduling
Operating Systems: Process Scheduling
 
Fundamentals of Computers
Fundamentals of ComputersFundamentals of Computers
Fundamentals of Computers
 
Concurrent transactions
Concurrent transactionsConcurrent transactions
Concurrent transactions
 
Tcp ip
Tcp ipTcp ip
Tcp ip
 
management of distributed transactions
management of distributed transactionsmanagement of distributed transactions
management of distributed transactions
 
Ch9: Memory Management
Ch9: Memory ManagementCh9: Memory Management
Ch9: Memory Management
 
SYNCHRONIZATION
SYNCHRONIZATIONSYNCHRONIZATION
SYNCHRONIZATION
 

Viewers also liked

Srt division (2)
Srt division (2)Srt division (2)
Srt division (2)miladce
 
Operating System 5
Operating System 5Operating System 5
Operating System 5tech2click
 
CPU scheduling algorithms in OS
CPU scheduling algorithms in OSCPU scheduling algorithms in OS
CPU scheduling algorithms in OSharini0810
 
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 (19)

Srt division (2)
Srt division (2)Srt division (2)
Srt division (2)
 
Sa by shekhar
Sa by shekharSa by shekhar
Sa by shekhar
 
CPU Scheduling Algorithms
CPU Scheduling AlgorithmsCPU Scheduling Algorithms
CPU Scheduling Algorithms
 
Cp usched 2
Cp usched  2Cp usched  2
Cp usched 2
 
Operating System 5
Operating System 5Operating System 5
Operating System 5
 
CPU scheduling algorithms in OS
CPU scheduling algorithms in OSCPU scheduling algorithms in OS
CPU scheduling algorithms in OS
 
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
 
OS_Ch6
OS_Ch6OS_Ch6
OS_Ch6
 
OSCh6
OSCh6OSCh6
OSCh6
 
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

SEO Case Study: How I Increased SEO Traffic & Ranking by 50-60% in 6 Months
SEO Case Study: How I Increased SEO Traffic & Ranking by 50-60%  in 6 MonthsSEO Case Study: How I Increased SEO Traffic & Ranking by 50-60%  in 6 Months
SEO Case Study: How I Increased SEO Traffic & Ranking by 50-60% in 6 MonthsIndeedSEO
 
Falcon's Invoice Discounting: Your Path to Prosperity
Falcon's Invoice Discounting: Your Path to ProsperityFalcon's Invoice Discounting: Your Path to Prosperity
Falcon's Invoice Discounting: Your Path to Prosperityhemanthkumar470700
 
Russian Call Girls In Gurgaon ❤️8448577510 ⊹Best Escorts Service In 24/7 Delh...
Russian Call Girls In Gurgaon ❤️8448577510 ⊹Best Escorts Service In 24/7 Delh...Russian Call Girls In Gurgaon ❤️8448577510 ⊹Best Escorts Service In 24/7 Delh...
Russian Call Girls In Gurgaon ❤️8448577510 ⊹Best Escorts Service In 24/7 Delh...lizamodels9
 
Call Girls In Noida 959961⊹3876 Independent Escort Service Noida
Call Girls In Noida 959961⊹3876 Independent Escort Service NoidaCall Girls In Noida 959961⊹3876 Independent Escort Service Noida
Call Girls In Noida 959961⊹3876 Independent Escort Service Noidadlhescort
 
FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756dollysharma2066
 
The Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai Kuwait
The Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai KuwaitThe Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai Kuwait
The Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai Kuwaitdaisycvs
 
Eluru Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Escort Service
Eluru Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Escort ServiceEluru Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Escort Service
Eluru Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Escort ServiceDamini Dixit
 
Mysore Call Girls 8617370543 WhatsApp Number 24x7 Best Services
Mysore Call Girls 8617370543 WhatsApp Number 24x7 Best ServicesMysore Call Girls 8617370543 WhatsApp Number 24x7 Best Services
Mysore Call Girls 8617370543 WhatsApp Number 24x7 Best ServicesDipal Arora
 
Falcon Invoice Discounting: Empowering Your Business Growth
Falcon Invoice Discounting: Empowering Your Business GrowthFalcon Invoice Discounting: Empowering Your Business Growth
Falcon Invoice Discounting: Empowering Your Business GrowthFalcon investment
 
👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...
👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...
👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...rajveerescorts2022
 
Phases of Negotiation .pptx
 Phases of Negotiation .pptx Phases of Negotiation .pptx
Phases of Negotiation .pptxnandhinijagan9867
 
Call Girls Kengeri Satellite Town Just Call 👗 7737669865 👗 Top Class Call Gir...
Call Girls Kengeri Satellite Town Just Call 👗 7737669865 👗 Top Class Call Gir...Call Girls Kengeri Satellite Town Just Call 👗 7737669865 👗 Top Class Call Gir...
Call Girls Kengeri Satellite Town Just Call 👗 7737669865 👗 Top Class Call Gir...amitlee9823
 
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...amitlee9823
 
How to Get Started in Social Media for Art League City
How to Get Started in Social Media for Art League CityHow to Get Started in Social Media for Art League City
How to Get Started in Social Media for Art League CityEric T. Tung
 
The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...
The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...
The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...Aggregage
 
JAYNAGAR CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRL
JAYNAGAR CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRLJAYNAGAR CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRL
JAYNAGAR CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRLkapoorjyoti4444
 
Cheap Rate Call Girls In Noida Sector 62 Metro 959961乂3876
Cheap Rate Call Girls In Noida Sector 62 Metro 959961乂3876Cheap Rate Call Girls In Noida Sector 62 Metro 959961乂3876
Cheap Rate Call Girls In Noida Sector 62 Metro 959961乂3876dlhescort
 
Call Girls In Majnu Ka Tilla 959961~3876 Shot 2000 Night 8000
Call Girls In Majnu Ka Tilla 959961~3876 Shot 2000 Night 8000Call Girls In Majnu Ka Tilla 959961~3876 Shot 2000 Night 8000
Call Girls In Majnu Ka Tilla 959961~3876 Shot 2000 Night 8000dlhescort
 
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service AvailableCall Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service AvailableSeo
 

Recently uploaded (20)

SEO Case Study: How I Increased SEO Traffic & Ranking by 50-60% in 6 Months
SEO Case Study: How I Increased SEO Traffic & Ranking by 50-60%  in 6 MonthsSEO Case Study: How I Increased SEO Traffic & Ranking by 50-60%  in 6 Months
SEO Case Study: How I Increased SEO Traffic & Ranking by 50-60% in 6 Months
 
Falcon's Invoice Discounting: Your Path to Prosperity
Falcon's Invoice Discounting: Your Path to ProsperityFalcon's Invoice Discounting: Your Path to Prosperity
Falcon's Invoice Discounting: Your Path to Prosperity
 
Russian Call Girls In Gurgaon ❤️8448577510 ⊹Best Escorts Service In 24/7 Delh...
Russian Call Girls In Gurgaon ❤️8448577510 ⊹Best Escorts Service In 24/7 Delh...Russian Call Girls In Gurgaon ❤️8448577510 ⊹Best Escorts Service In 24/7 Delh...
Russian Call Girls In Gurgaon ❤️8448577510 ⊹Best Escorts Service In 24/7 Delh...
 
Call Girls In Noida 959961⊹3876 Independent Escort Service Noida
Call Girls In Noida 959961⊹3876 Independent Escort Service NoidaCall Girls In Noida 959961⊹3876 Independent Escort Service Noida
Call Girls In Noida 959961⊹3876 Independent Escort Service Noida
 
FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756
 
The Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai Kuwait
The Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai KuwaitThe Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai Kuwait
The Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai Kuwait
 
Eluru Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Escort Service
Eluru Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Escort ServiceEluru Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Escort Service
Eluru Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Escort Service
 
Mysore Call Girls 8617370543 WhatsApp Number 24x7 Best Services
Mysore Call Girls 8617370543 WhatsApp Number 24x7 Best ServicesMysore Call Girls 8617370543 WhatsApp Number 24x7 Best Services
Mysore Call Girls 8617370543 WhatsApp Number 24x7 Best Services
 
Falcon Invoice Discounting: Empowering Your Business Growth
Falcon Invoice Discounting: Empowering Your Business GrowthFalcon Invoice Discounting: Empowering Your Business Growth
Falcon Invoice Discounting: Empowering Your Business Growth
 
👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...
👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...
👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...
 
Phases of Negotiation .pptx
 Phases of Negotiation .pptx Phases of Negotiation .pptx
Phases of Negotiation .pptx
 
Call Girls Kengeri Satellite Town Just Call 👗 7737669865 👗 Top Class Call Gir...
Call Girls Kengeri Satellite Town Just Call 👗 7737669865 👗 Top Class Call Gir...Call Girls Kengeri Satellite Town Just Call 👗 7737669865 👗 Top Class Call Gir...
Call Girls Kengeri Satellite Town Just Call 👗 7737669865 👗 Top Class Call Gir...
 
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
 
How to Get Started in Social Media for Art League City
How to Get Started in Social Media for Art League CityHow to Get Started in Social Media for Art League City
How to Get Started in Social Media for Art League City
 
The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...
The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...
The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...
 
JAYNAGAR CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRL
JAYNAGAR CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRLJAYNAGAR CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRL
JAYNAGAR CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRL
 
Cheap Rate Call Girls In Noida Sector 62 Metro 959961乂3876
Cheap Rate Call Girls In Noida Sector 62 Metro 959961乂3876Cheap Rate Call Girls In Noida Sector 62 Metro 959961乂3876
Cheap Rate Call Girls In Noida Sector 62 Metro 959961乂3876
 
Falcon Invoice Discounting platform in india
Falcon Invoice Discounting platform in indiaFalcon Invoice Discounting platform in india
Falcon Invoice Discounting platform in india
 
Call Girls In Majnu Ka Tilla 959961~3876 Shot 2000 Night 8000
Call Girls In Majnu Ka Tilla 959961~3876 Shot 2000 Night 8000Call Girls In Majnu Ka Tilla 959961~3876 Shot 2000 Night 8000
Call Girls In Majnu Ka Tilla 959961~3876 Shot 2000 Night 8000
 
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service AvailableCall Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
 

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