uniprocessor scheduling algorithms Process States Types of Scheduling Short-Term Scheduling Why Why Why

Your may download all of the tables(key points) of this article by clicking this link:
PDF Quick Reference:
Download tables

In this article, we are going to introduce several short-term scheduling algorithms that are widely used in uniprocessor computers. After reading this article, your should be able to answer the following questions: What’s process state? What’s short-term scheduling? When to do short-term scheduling? What kinds of scheduling algorithms do we currently have? How do we choose a scheduling algorithm and based on what criteria? The following table indicates which sections in this article are trying to answer these questions correspondingly.
Contents Indicating Table

Process States

  • New: A process is created.
    Program code are moved from disk to main memory.
  • Ready: The process is waiting to be scheduling to a processor.
    Program code reside in main memory.
  • Running: Instructions are being executed in CPU.
    Instructions reside in CPU.
  • Waiting: The process is blocked and waiting for some events to occur(signal)
    Program code are in main memory or has been swapped out to virtual memory.
  • Terminated: The process has finished execution.
    Program code are removed from memory.

This is the state transition diagram of the process states.
State Transition Diagram

The table below shows where do program code mainly reside at each state.
Program Code Location

Types of Scheduling

There are three kinds of scheduling including long-term scheduling , medium-term scheduling and short-term scheduling. This article is mainly focus on short-term scheduling.

This table shows when do we do the three scheduling in terms of state transitions.
Scheduling and State Transition

We mark them on the state transition diagram:
Scheduling on State Transition

Short-Term Scheduling

Scheduling Criteria

There are a bunch of scheduling criteria that we need to consider when choosing a scheduling algorithm.

  • CPU utilization (u%)
  • Throughput (process/second)
  • Turnaround time (seconds/process)
  • Waiting time (seconds)
  • Response time (seconds)
  • Deadline
  • Fairness
  • Predictability
  • Policy enforcement
  • Balance

Criteria for Different Systems

Different systems should follow different criteria based on their own requirements.
Criteria for Different Systems

Scheduling Algorithms

We will introduce four scheduling algorithms with examples. In next section, we will explain the details of these algorithms.

1. First-Come-First-Serve (FCFS)

Selection Function: Select the process with the minimum arrival time. (Non-preemptive)
Example for FCFS:
Suppose there are four processes whose arrival time and service time are listed in the table.
FCFS Processes Table
The scheduling result in Gantt chart:
FCFS Scheduling Result

2. Round-Robin (RR)

Selection Function: Each process execute for fixed length of time quantum. (Preemptive)
Example for RR:
Suppose there are four processes whose arrival time and service time are listed in the table.
Round-Robin Processes Table
The scheduling result in Gantt chart:
Round-Robin Scheduling Result

3. Shortest-Job-First (SJF)

Selection Function: Select the process with the minimum service time (Non-preemptive)
Example for SJF:
Suppose there are four processes whose arrival time and service time are listed in the table.
SJF Processes Table
The scheduling result in Gantt chart:
SJF Scheduling Result

4. Preemptive-Shortest-Job-First (PSJF)

Selection Function: Select the process with the minimum remaining service time (Preemptive)
Example for PSJF:
Suppose there are three processes whose arrival time and service time are listed in the table.
PSJF Processes Table
The scheduling result in Gantt chart:
PSJF Scheduling Result

Scheduling Algorithm Properties

We define some terms first.

  • a : arrival time of a process
  • e : time spent in execution so far
  • s : total service time required by the process, including e

The following table shows the corresponding properties to the scheduling algorithms.
Scheduling Algorithm Properties

Scheduling Algorithm Selection

Based on the criteria for different systems and scheduling algorithm properties, we can decide what kind of algorithms we should choose for each kind of systems. As is shown from below:
Systems and Scheduling Algorithms

Why Why Why

Why Multiprograming

Some processes are CPU bound, and some are I/O bound. An I/O bound process will be blocked when it tries to do I/O. To improve CPU utilization rate, engineers proposed the concept of Multiprograming. That is to say — we load many processes into the main memory at the same time. When a running process is blocked by I/O operation, we switch to run other processes. Multiprograming is the root cause that we need to do short-term scheduling.

What’s the differences between Multiprograming and Multithreading

Multiprograming is for improving CPU utilization, while Multithreading is for many other reasons. For example: share resources, parallelism, simplify code structure, improve concurrency and many others.