Introduction to CPU Scheduling Concepts

Aug 4, 2024

Operating System Series - Lecture 1: CPU Scheduling

Introduction

  • Start of the operating system series
  • Focus on the first chapter: CPU scheduling
  • Topics covered:
    • What is a process?
    • How processes run in the system

What is an Operating System (OS)?

  • Definition: A software that acts as an intermediary between the user and computer hardware
  • Importance: Essential for using computer hardware (CPU, hard disk, etc.) and running applications
  • Functions:
    • Provides an interface between user and hardware
    • Offers utilities (APIs) for software development

Types of Operating Systems

  • Multi-user OS: Allows multiple users to use the same CPU and hard disk simultaneously
  • Embedded OS: Used in microcontrollers and embedded systems like intelligent systems in cars, air conditioners, etc.

Key Components in a Computer System

  • CPU (Central Processing Unit): Executes instructions
  • RAM (Random Access Memory): Main memory where running programs reside
  • I/O Devices: Input-output devices like keyboards, mice, monitors, etc.

Multi-programming Operating System

  • Definition: Allows multiple processes to be in the main memory simultaneously
  • Benefits: Increases CPU utilization by having another process ready to run when one is waiting for I/O operations
  • Types:
    • Non-preemptive: Running process leaves CPU only when it wishes
    • Preemptive: Running process can be taken out of the CPU forcefully

Process vs Program

  • Process: Program under execution with runtime activities added (e.g., stack, heap, data section)
  • Program: Code without runtime activities

Process Structure

  • Four Sections: Code, Data, Heap, Stack
  • Purpose of Sections:
    • Code: Stores the program instructions
    • Data: Stores global and static variables
    • Heap: Used for dynamic memory allocation
    • Stack: Stores local variables, function parameters, return addresses

Process Control Block (PCB)

  • Definition: Data structure that stores all information about a process
  • Contents:
    • Process ID (PID)
    • Device list
    • Process type
    • Memory boundaries
    • Priority
    • State
    • List of files
    • Register values
  • Purpose: Allows OS to control and manage processes

Context Switch

  • Definition: Process where CPU switches from running one process to another
  • Steps:
    • Context Save: Save current process's register values to its PCB
    • Context Load: Load next process’s register values from its PCB to CPU registers
  • Dispatcher: Performs the context switch

Process States

  • New: Process not yet admitted to main memory
  • Ready: Process waiting for CPU allocation
  • Running: Process currently being executed by the CPU
  • Blocked/Waiting: Process waiting for I/O operations or specific events
  • Terminated: Process has finished execution
  • State Transitions:
    • New β†’ Ready: Process admitted
    • Ready β†’ Running: Process dispatched to CPU
    • Running β†’ Terminated: Process completed
    • Running β†’ Blocked: Process waiting for I/O
    • Blocked β†’ Ready: I/O completed
    • Running β†’ Ready: Process preempted
  • Preemptive vs Non-preemptive:
    • Preemptive allows forced removal from CPU
    • Non-preemptive process leaves CPU only by its own wish

Types of Process Transitions

  • Voluntary (Initiated by process):
    • Running β†’ Terminated
    • Running β†’ Blocked
  • Involuntary (Initiated by OS):
    • New β†’ Ready
    • Ready β†’ Running
    • Running β†’ Ready
    • Blocked β†’ Ready

Next Lecture Preview

  • Discussion on three types of schedulers
  • Introduction to CPU scheduling algorithms
  • Focus on First-Come, First-Served (FCFS) algorithm
  • Importance of practice for numerical problems related to CPU scheduling