Overview

Multiprogramming OSes have periods of idling on the CPU and executing work on I/O processes or CPU processes. Idling allows for scheduling of processes.

Schedulers

Schedulers are part of the OS dispatcher. It selects a few processes from memory that are ready to execute.

Goals

  • Maximize throughput and CPU utilization
  • Minimize turnaround, waiting, and response time
  • Be fair to all processes and users

Scheduling that happens when a process switches from the running to waiting state or when a process that terminates is non-preemptive.

Scheduling that happens when a process switches from the running to ready state, or the waiting/new to ready state is preemptive.

Dispatcher

Scheduler is a sub-part of the dispatcher

Dispatcher Queues

Methods of Evaluation

Deterministic Evaluation

Queueing Models

Simulations

Scheduling Algorithms

First-Come First Served

Also known as FCFS, it assigns CPU time based on order of arrival. It is implemented using a FIFO. There is no preemption, i.e. no processes are interrupted.

This can be used in a multiprogramming OS, but is not very efficient.

Pros

  • Straightforward, and simple to write and understand

Cons

  • Average waiting time may be too long
  • Cannot balance CPU-bound and I/O-bound processes
  • Cannot be used for time-sharing systems

There can be a huge variation in when processes arrive, which may affect waiting time. The convoy effect can also apply where short processes may be scheduled behind long processes, making their time to completion much longer.

Shortest-Job-First

Also known as SJF, this orders each process based on the length of the next CPU burst. It allocates CPU to the process from the front of the list. This is non-preemptive and a greedy algorithm.

It is a good benchmark to evaluate any other algorithms.

Pros

  • SJF is optimal, it achieves the minimum waiting time for a given set of processes.

Cons

  • Difficult to know the length of the next process
  • This can lead to starvation

SJF can use model based prediction to help solve the issue of knowing the length of the next process.

Starvation can occur if processes that are added to the ready queue are continuously smaller and smaller.

Estimated Length of Next CPU Burst Algorithm

The model uses the "history" of processes run and uses and exponential average to predict the next burst. The exponential average gives higher weightage to the lengths of recent processes.

This is not commonly used, but can be used as a baseline for testing other algorithms.

The basic formula is as follows

τn+1=αtn+(1α)τn

Where

Note

τn+1 is initialized to a random value.

Preemptive SJF

This has newer and shorter processes preempt longer currently running processes.

Priority Based

Pros
Cons

Round Robin (RR)

Pros
Cons

Multilevel Queue Scheduling

Pros
Cons

Multilevel Feedback Queue Scheduling

Pros
Cons

Definitions

CPU Utilization

Percentage of time that CPU is busy.


Throughput

The number of processes that complete their execution per unit of time.


Turnaround Time

Amount of time to execute a particular process (time delta of submission time to completion).

turnaround_time = completion_time - submission_time

Waiting Time

Amount of time a process has been waiting in the ready queue.

waiting_time = completion_time - submission_time - time_burst

Response Time

Amount of time it takes from when a request was submitted until the first response is produced.

Reference

  1. Kulkarni, Prasad Various Lectures The University of Kansas 2024

Related

  1. Processes
  2. OS Overview