BCS401 Operating System Semester IV · AY 2025-26 onward
Unit 3 · CPU Scheduling, Threads & Deadlocks

Lecture 3: Schedulers & PCB

Learning outcomes

  • Differentiate between long‑, medium‑ and short‑term schedulers and describe the contents of a process control block.
Lecture Notes

Main content

Schedulers & Process Control Block (PCB)

Learning Outcome

Differentiate between long-, medium-, and short-term schedulers and describe the contents of a Process Control Block (PCB).


Introduction

In a multiprogramming operating system, several processes may exist at the same time. Some are waiting to enter memory, some are ready for execution, some are waiting for I/O, and one may be running on the CPU. The operating system therefore needs mechanisms to select processes at different stages. These selection mechanisms are called schedulers.

Along with scheduling, the operating system must also maintain complete information about every process. This information is stored in a data structure called the Process Control Block (PCB). Without the PCB, the operating system would not be able to stop, resume, schedule, or manage a process correctly.

Key Idea

Schedulers decide which process should move forward. The PCB stores all essential information about that process.

Why Multiple Schedulers Are Needed

Process management in an operating system does not happen at only one stage. A process may first be admitted into the system, then selected for CPU execution, and later even be removed from memory and brought back again. Since these tasks are different in purpose and frequency, operating systems use different schedulers.

Long-Term Scheduler

Also called the job scheduler, it decides which jobs should be admitted into the system for execution. It selects processes from the job pool on secondary storage and loads them into memory.

  • Controls the degree of multiprogramming.
  • Maintains a good mix of CPU-bound and I/O-bound processes.
  • Invoked infrequently.

Short-Term Scheduler

Also called the CPU scheduler, it selects one process from the ready queue and allocates the CPU to it. This scheduler is central to CPU multitasking.

  • Directly affects response time and CPU utilization.
  • Must work very quickly (millisecond scale).
  • Invoked very frequently.

Medium-Term Scheduler

Associated with virtual memory and swapping. It temporarily removes a process from main memory to reduce congestion and later brings it back.

  • Suspends processes to reduce memory load.
  • Reintroduces processes when memory frees up.
  • Balances system performance dynamically.

Comparison of the Three Schedulers

Scheduler Main Function Execution Frequency Speed Requirement
Long-Term Admits jobs into main memory Less frequent (minutes/seconds) Moderate
Short-Term Selects process for the CPU Very frequent (milliseconds) Very Fast
Medium-Term Swaps processes in and out Occasional Moderate

Process Control Block (PCB)

Each process in the operating system is represented by a Process Control Block (PCB), sometimes called a Task Control Block. It is the core data structure that stores all essential, unique information about a specific process.

Contents of a PCB

  • Process State: Tracks current state (new, ready, running, waiting, or terminated).
  • Program Counter: The memory address of the next instruction to be executed.
  • CPU Registers: Saves the contents of accumulators, index registers, and stack pointers so execution can resume exactly where it left off.
  • CPU Scheduling Info: Process priority, pointers to scheduling queues, and other parameters.
  • Memory-Management Info: Page tables, segment tables, base, and limit register values.
  • Accounting Information: CPU time consumed, time limits, account numbers, and process numbers.
  • I/O Status Information: List of open files, allocated I/O devices, etc.
In Simple Words

The PCB is the "ID badge and medical chart" for a process. It stores everything the OS needs to pause a process, go do something else, and restart it later without losing progress.

PCB and Context Switching

A context switch occurs when the CPU changes from one process to another. During this operation, the state of the currently running process is saved into its PCB, and the saved state of the next process is loaded from its respective PCB.

Because of this, the PCB is central to multitasking. Without it, the OS would not know where to resume a suspended process.


Worked Example: Schedulers & PCB in Action

Consider three processes: P1, P2, and P3.

  1. P1 and P2 are waiting on disk. The long-term scheduler admits them into memory. They now enter the ready queue.
  2. The short-term scheduler selects P1. The dispatcher allocates the CPU to P1, moving it to the running state.
  3. P1 requests disk I/O. Before P1 leaves the CPU, the OS saves its program counter, registers, and state into P1's PCB. P1 moves to the waiting state.
  4. The short-term scheduler selects P2. The OS loads the saved execution details from P2's PCB and gives the CPU to P2.
  5. Main memory becomes heavily loaded. The medium-term scheduler temporarily removes P2 from memory (swapping it to disk). P2 is suspended.
  6. When P1’s I/O completes... it returns to the ready queue. Later, the short-term scheduler selects P1, and its state is restored from its PCB.

One-Page Summary: Schedulers & PCB

An OS uses different schedulers because process selection occurs at varying frequencies and stages:

  • Long-term scheduler: Admits jobs from disk to memory (controls degree of multiprogramming).
  • Short-term scheduler: Selects a process from the ready queue for the CPU (must be extremely fast).
  • Medium-term scheduler: Swaps processes between memory and disk to manage RAM limits.

A Process Control Block (PCB) is the data structure representing a process. It tracks everything needed to manage execution, including: Process state, Program Counter, CPU registers, Memory limits, and I/O status.

The PCB is heavily utilized during a context switch. When the CPU swaps processes, the outgoing process writes its current progress to its PCB, and the incoming process reads its progress from its own PCB to resume execution seamlessly.