Docsity

Operating System Process Scheduling: CPU Algorithms & Optimization, Slides of Operating Systems

Partial preview of the text

Download Operating System Process Scheduling: CPU Algorithms & Optimization and more Slides Operating Systems in PDF only on Docsity!

Lecture#

Process Scheduling

Dr. Shariq BASHIR

Foundation University Islamabad

Operating Systems

FALL 2019

Objective of CPU Scheduling

  • (^) The objective of CPU Scheduling

is to switch the CPU among

multiple processes

  • (^) This increases the productivity

of CPU by providing an illusion

to users that multiple processes

are running on a system

2

When to select a new process to

Run

  • (^) Four circumstances 4 New New Exit Exit Admit Release Running Running Ready Ready Dispatch Time-out Blocked Blocked Event occurs Event wait
  1. Wait for I/O
  2. Interrupt occurs, move from Running to Ready
  3. Event I/O Completion
  4. A Process terminates

Non Preemptive Scheduling

  • (^) Once the CPU has been allocated to a

process

  • (^) The process keeps it until
    • (^) It Terminates
    • (^) Or has to wait for I/O
  • (^) There is no way, to get the CPU back,

FORCEFULLY

5

Preemptive Scheduling

  • (^) Possible to get the CPU back from a

process, even if the process has not

completed its execution.

  • (^) All four cases, 1,2,3 and 4 7

Preemptive Scheduling

8 New New Exit Exit Admit Release Running Running Ready Ready Dispatch Time-out Blocked Blocked Event occurs Event wait

  1. Wait for I/O
    1. Interrupt occurs, move from Running to Ready
  2. Event I/O Completion
  3. A Process terminates

Scheduling Optimization

Criteria

• Different CPU-scheduling algorithms

have different properties

• The choice of a particular algorithm

may favor one class of processes over

another

10

Scheduling Optimization

Criteria

• Scheduling algorithms are compared

on the basis of following optimization

criteria

Throughput

Turnaround time (Avg. Completion

time)

Waiting time

Optimization Criteria

  • (^) Throughput
    • (^) Number of processes completed

per unit time

  • (^) E.g. long processes
    • 1 process / hr
  • (^) Short processes
    • 10 processes / hr 13

Optimization Criteria

  • Waiting Time
    • Sum of the periods spent waiting in the Ready Queue 14

Standard Scheduling

Algorithms

First come, First serve (FCFS)

Round-Robin Scheduling

Priority Scheduling

Shortest Job First (SJF)

16

First come, First serve

  • (^) Simplest scheduling algorithm:
    • (^) Run jobs in order that they arrive
  • (^) Non-Preemptive
    • (^) A Process keeps CPU until finish or

I/O

  • (^) Advantage:
    • (^) Simple to Implement 17

First come, First serve

  • (^) Now if they arrive in the order B, C, A 19

Average Waiting

Time

cpu
time 1 3 103
B C^ A

FCFS Convoy effect

  • (^) A CPU bound Process will hold CPU until
    • (^) Terminates
    • (^) Or it causes an I/O burst
      • (^) Rare occurrence, since the process is CPU- bound
  • (^) Long periods where no I/O requests,
    • (^) CPU will be 100% busy but
    • (^) I/O devices will be free 20