SlideShare a Scribd company logo
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 (20)

PPT
Cache memory
Faiq Ali Sayed
 
PPTX
Critical section problem in operating system.
MOHIT DADU
 
PPTX
Operating system 31 multiple processor scheduling
Vaibhav Khanna
 
PPTX
Multiprocessing, difference, advantages and disadvantages
crella7557
 
PPT
Process scheduling : operating system ( Btech cse )
HimanshuSharma1389
 
PPT
scheduling
Gaurav Shinde
 
PPT
Processor / CPU Scheduling
Izaz Roghani
 
PDF
Distributed Operating System_1
Dr Sandeep Kumar Poonia
 
PPT
Process Synchronization
Sonali Chauhan
 
PPT
Deadlock
Rajandeep Gill
 
PPTX
Priority Scheduling
JawadHaider36
 
PDF
Operating Systems - memory management
Mukesh Chinta
 
PPT
Part 1 - PROCESS CONCEPTS
priyasoundar
 
PPTX
Metrics for project size estimation
Nur Islam
 
PDF
CSI-503 - 11.Distributed Operating System
ghayour abbas
 
PPT
Chapter 3 - Top Level View of Computer / Function and Interconection
César de Souza
 
PPTX
Cache memory ppt
Arpita Naik
 
PPTX
Scheduling algorithms
Paurav Shah
 
PPT
3.Medium Access Control
Sonali Chauhan
 
PDF
Process Scheduling in OS
Rashmi Bhat
 
Cache memory
Faiq Ali Sayed
 
Critical section problem in operating system.
MOHIT DADU
 
Operating system 31 multiple processor scheduling
Vaibhav Khanna
 
Multiprocessing, difference, advantages and disadvantages
crella7557
 
Process scheduling : operating system ( Btech cse )
HimanshuSharma1389
 
scheduling
Gaurav Shinde
 
Processor / CPU Scheduling
Izaz Roghani
 
Distributed Operating System_1
Dr Sandeep Kumar Poonia
 
Process Synchronization
Sonali Chauhan
 
Deadlock
Rajandeep Gill
 
Priority Scheduling
JawadHaider36
 
Operating Systems - memory management
Mukesh Chinta
 
Part 1 - PROCESS CONCEPTS
priyasoundar
 
Metrics for project size estimation
Nur Islam
 
CSI-503 - 11.Distributed Operating System
ghayour abbas
 
Chapter 3 - Top Level View of Computer / Function and Interconection
César de Souza
 
Cache memory ppt
Arpita Naik
 
Scheduling algorithms
Paurav Shah
 
3.Medium Access Control
Sonali Chauhan
 
Process Scheduling in OS
Rashmi Bhat
 

Viewers also liked (19)

PPTX
Srt division (2)
miladce
 
PPT
Sa by shekhar
shekhar1991
 
PPT
CPU Scheduling Algorithms
Shubhashish Punj
 
PPT
Cp usched 2
nidsrajdev
 
PPT
Operating System 5
tech2click
 
PPT
Scheduling algorithms
Chankey Pathak
 
PPTX
CPU scheduling algorithms in OS
harini0810
 
PPS
Detoxification
guest38a88
 
PPS
Gunas quiz
dividisa
 
PDF
4838281 operating-system-scheduling-on-multicore-architectures
Islam Samir
 
PPTX
Eating for Balance, The Six Tastes of Ayurveda and What to Eat for Your Dosha
Pamela Quinn
 
PPTX
Management of Common Disorders - 120412
Dhananjay Arankalle
 
PPT
06 The Three Temperaments Edited
Yatin Mota
 
PPSX
VARNA DHARMA
Ananda Ang
 
PPTX
Real time Scheduling in Operating System for Msc CS
Thanveen
 
PPT
Cpu Scheduling Galvin
Sonali Chauhan
 
PDF
5 Process Scheduling
Dr. Loganathan R
 
PDF
Chapter6
Denis Nsiimenta
 
Srt division (2)
miladce
 
Sa by shekhar
shekhar1991
 
CPU Scheduling Algorithms
Shubhashish Punj
 
Cp usched 2
nidsrajdev
 
Operating System 5
tech2click
 
Scheduling algorithms
Chankey Pathak
 
CPU scheduling algorithms in OS
harini0810
 
Detoxification
guest38a88
 
Gunas quiz
dividisa
 
4838281 operating-system-scheduling-on-multicore-architectures
Islam Samir
 
Eating for Balance, The Six Tastes of Ayurveda and What to Eat for Your Dosha
Pamela Quinn
 
Management of Common Disorders - 120412
Dhananjay Arankalle
 
06 The Three Temperaments Edited
Yatin Mota
 
VARNA DHARMA
Ananda Ang
 
Real time Scheduling in Operating System for Msc CS
Thanveen
 
Cpu Scheduling Galvin
Sonali Chauhan
 
5 Process Scheduling
Dr. Loganathan R
 
Chapter6
Denis Nsiimenta
 
Ad

Similar to Os module 2 ba (20)

PPTX
Operating systems - Processes Scheduling
Dr. Chandrakant Divate
 
PPTX
CPU Scheduling Lecture 5 - 6.pptx
Harry83774
 
PDF
CPU Scheduling
Farhat Shaikh
 
PPT
OS-operating systems- ch05 (CPU Scheduling) ...
Dr. Mazin Mohamed alkathiri
 
PDF
ch5_CPU Scheduling_part1.pdf
SonaliAjankar
 
PPTX
CPU scheduling
Amir Khan
 
PDF
Process Scheduling
International Islamic University
 
PDF
OS Process Chapter 3.pdf
Kp Sharma
 
PPT
ch6- CPU scheduling https://www.slideshare.net/slideshow/operating-system-18-...
ssuserc35fa4
 
PPT
Process Scheduling in Ope Spptystems rating
Aryan904173
 
PPT
Process management in os
Miong Lazaro
 
PPTX
operating system scheduling concept lec2
thakurnishant1903200
 
PPTX
Presentation by adeel
Goodthingbetter
 
PPTX
Operating system
raeesa khan
 
PPT
ch_scheduling (1).ppt
Farhanahmad540205
 
PDF
cpu schduling ppt.pdf
SangeethaBS4
 
PPT
Cpu scheduling
Prakash Sir
 
PPTX
Preemptive process example.pptx
jamilaltiti1
 
PPTX
Operating system
Lovly Angel
 
Operating systems - Processes Scheduling
Dr. Chandrakant Divate
 
CPU Scheduling Lecture 5 - 6.pptx
Harry83774
 
CPU Scheduling
Farhat Shaikh
 
OS-operating systems- ch05 (CPU Scheduling) ...
Dr. Mazin Mohamed alkathiri
 
ch5_CPU Scheduling_part1.pdf
SonaliAjankar
 
CPU scheduling
Amir Khan
 
OS Process Chapter 3.pdf
Kp Sharma
 
ch6- CPU scheduling https://www.slideshare.net/slideshow/operating-system-18-...
ssuserc35fa4
 
Process Scheduling in Ope Spptystems rating
Aryan904173
 
Process management in os
Miong Lazaro
 
operating system scheduling concept lec2
thakurnishant1903200
 
Presentation by adeel
Goodthingbetter
 
Operating system
raeesa khan
 
ch_scheduling (1).ppt
Farhanahmad540205
 
cpu schduling ppt.pdf
SangeethaBS4
 
Cpu scheduling
Prakash Sir
 
Preemptive process example.pptx
jamilaltiti1
 
Operating system
Lovly Angel
 
Ad

More from Gichelle Amon (20)

PPTX
Kerberos
Gichelle Amon
 
PPT
Network security
Gichelle Amon
 
PPT
Os module 2 d
Gichelle Amon
 
PPT
Os module 2 c
Gichelle Amon
 
PPT
Image segmentation ppt
Gichelle Amon
 
PPT
Lec3 final
Gichelle Amon
 
PPTX
Lec 3
Gichelle Amon
 
PPT
Lec2 final
Gichelle Amon
 
PPTX
Lec 4
Gichelle Amon
 
PPT
Lec1 final
Gichelle Amon
 
DOC
Module 3 law of contracts
Gichelle Amon
 
PPT
Transport triggered architecture
Gichelle Amon
 
PPT
Time triggered arch.
Gichelle Amon
 
PPT
Subnetting
Gichelle Amon
 
PPT
Os module 2 c
Gichelle Amon
 
PPT
Lec5
Gichelle Amon
 
PPT
Delivery
Gichelle Amon
 
PPT
Addressing
Gichelle Amon
 
PPT
6 spatial filtering p2
Gichelle Amon
 
PPT
5 spatial filtering p1
Gichelle Amon
 
Kerberos
Gichelle Amon
 
Network security
Gichelle Amon
 
Os module 2 d
Gichelle Amon
 
Os module 2 c
Gichelle Amon
 
Image segmentation ppt
Gichelle Amon
 
Lec3 final
Gichelle Amon
 
Lec2 final
Gichelle Amon
 
Lec1 final
Gichelle Amon
 
Module 3 law of contracts
Gichelle Amon
 
Transport triggered architecture
Gichelle Amon
 
Time triggered arch.
Gichelle Amon
 
Subnetting
Gichelle Amon
 
Os module 2 c
Gichelle Amon
 
Delivery
Gichelle Amon
 
Addressing
Gichelle Amon
 
6 spatial filtering p2
Gichelle Amon
 
5 spatial filtering p1
Gichelle Amon
 

Recently uploaded (20)

PPTX
Chapter 3 Distributive Negotiation: Claiming Value
badranomar1990
 
PPTX
The Rise of Artificial Intelligence pptx
divyamarya13
 
PDF
Using Innovative Solar Manufacturing to Drive India's Renewable Energy Revolu...
Insolation Energy
 
PDF
Followers to Fees - Social media for Speakers
Corey Perlman, Social Media Speaker and Consultant
 
PPTX
Andrew C. Belton, MBA Experience Portfolio July 2025
Andrew C. Belton
 
PDF
Driving the Energy Transition India’s Top Renewable Energy Solution Providers...
Essar Group
 
PDF
Gregory Felber - A Dedicated Researcher
Gregory Felber
 
PPTX
E-commerce and its impact on business.
pandeyranjan5483
 
PDF
ANÁLISIS DE COSTO- PAUCAR RIVERA NEISY.pdf
neisypaucarr
 
PDF
Top 10 Corporates in India Investing in Sustainable Energy.pdf
Essar Group
 
PDF
Alan Stalcup - Principal Of GVA Real Estate Investments
Alan Stalcup
 
PDF
The New Zealand Business Sales Report 2025_compressed.pdf
charlie630518
 
PDF
Agentic AI: The Autonomous Upgrade Your AI Stack Didn’t Know It Needed
Amnic
 
PDF
GenAI for Risk Management: Refresher for the Boards and Executives
Alexei Sidorenko, CRMP
 
PPTX
Social Media Marketing for Business Growth
vidhi622006
 
PDF
MBA-I-Year-Session-2024-20hzuxutiytidydy
cminati49
 
PDF
A Study on Analysing the Financial Performance of AU Small Finance and Ujjiva...
AI Publications
 
PDF
Retinal Disorder Treatment Market 2030: The Impact of Advanced Diagnostics an...
Kumar Satyam
 
PPTX
FINAL _ DB x Forrester x Workday Webinar Buying Groups July 2025 (1).pptx
smarvin1
 
PDF
From Fossil to Future Green Energy Companies Leading India’s Energy Transitio...
Essar Group
 
Chapter 3 Distributive Negotiation: Claiming Value
badranomar1990
 
The Rise of Artificial Intelligence pptx
divyamarya13
 
Using Innovative Solar Manufacturing to Drive India's Renewable Energy Revolu...
Insolation Energy
 
Followers to Fees - Social media for Speakers
Corey Perlman, Social Media Speaker and Consultant
 
Andrew C. Belton, MBA Experience Portfolio July 2025
Andrew C. Belton
 
Driving the Energy Transition India’s Top Renewable Energy Solution Providers...
Essar Group
 
Gregory Felber - A Dedicated Researcher
Gregory Felber
 
E-commerce and its impact on business.
pandeyranjan5483
 
ANÁLISIS DE COSTO- PAUCAR RIVERA NEISY.pdf
neisypaucarr
 
Top 10 Corporates in India Investing in Sustainable Energy.pdf
Essar Group
 
Alan Stalcup - Principal Of GVA Real Estate Investments
Alan Stalcup
 
The New Zealand Business Sales Report 2025_compressed.pdf
charlie630518
 
Agentic AI: The Autonomous Upgrade Your AI Stack Didn’t Know It Needed
Amnic
 
GenAI for Risk Management: Refresher for the Boards and Executives
Alexei Sidorenko, CRMP
 
Social Media Marketing for Business Growth
vidhi622006
 
MBA-I-Year-Session-2024-20hzuxutiytidydy
cminati49
 
A Study on Analysing the Financial Performance of AU Small Finance and Ujjiva...
AI Publications
 
Retinal Disorder Treatment Market 2030: The Impact of Advanced Diagnostics an...
Kumar Satyam
 
FINAL _ DB x Forrester x Workday Webinar Buying Groups July 2025 (1).pptx
smarvin1
 
From Fossil to Future Green Energy Companies Leading India’s Energy Transitio...
Essar Group
 

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