🧠 What is a Scheduler?

A Scheduler in an Operating System is the component that selects which process gets access to the CPU or resources next, based on a defined policy or algorithm.

In short: it decides what to run, when, and for how long.


πŸ” Types of Schedulers

There are 3 primary types, each working at a different stage of process lifecycle:


1. 🧱 Long-Term Scheduler (Admission Scheduler)

  • Decides which jobs/processes to admit into the system (i.e., into memory and ready queue).

  • Controls degree of multiprogramming.

  • Used mostly in batch systems or when the OS is under heavy load.

| Role | Admit new processes from Job Queue β†’ Ready Queue |
| Frequency | Infrequent |
| Controlled By | OS policy (e.g., memory limits, system load) |


2. ⚑ Short-Term Scheduler (CPU Scheduler)

  • The most important scheduler in modern OS.

  • Decides which ready process gets the CPU next.

  • Operates very frequently (milliseconds or less).

  • Must be fast and efficient.

| Role | Picks from Ready Queue β†’ CPU |
| Frequency | Very high (every context switch, timer interrupt) |
| Examples | Round Robin, Priority Scheduling, SJF, etc. |


3. πŸ”„ Medium-Term Scheduler

  • Optional β€” used in swapping systems.

  • Temporarily removes processes from memory (RAM) and puts them on disk to free up space.

  • Later, it can resume these processes.

| Role | Moves processes in and out of memory (Ready ↔ Suspended) |
| Used When | System is low on RAM |
| Rare | Used in embedded/legacy or highly loaded systems |


🎯 Goals of Scheduling

GoalDescription
⏱️ Maximize CPU UtilizationKeep CPU as busy as possible
βš–οΈ FairnessNo starvation
πŸš€ Maximize ThroughputComplete as many processes as possible
πŸ•°οΈ Minimize Turnaround TimeFrom submission β†’ completion
βŒ› Minimize Waiting TimeTime spent in ready queue
πŸ” Minimize Response TimeFirst visible output for interactive users

🧩 Real World Example

Let’s say 5 processes are in the ready queue:

P1, P2, P3, P4, P5

Depending on the scheduling algorithm:

  • FCFS β†’ pick P1

  • Priority β†’ pick the one with highest priority

  • Round Robin β†’ rotate every x ms

  • SJF β†’ pick the one with shortest burst time

The CPU Scheduler (short-term) handles all this, extremely fast.


βš™οΈ CPU Scheduling Flow Diagram

[ Ready Queue ] β†’ Scheduler β†’ [ CPU ]
                     ↑
              Based on Scheduling Algorithm

🧠 Interview-Ready Definition:

A Scheduler is an OS module that makes decisions about which process or task to run next, based on priority, fairness, and system efficiency. It can be long-term (job admission), short-term (CPU allocation), or medium-term (memory swapper).