🧠 What is Process Scheduling?
Process Scheduling is the OS mechanism that selects which ready process should run on the CPU next.
Since we have:
-
More processes than CPUs, and
-
Only one process per CPU core at a time,
the OS needs a smart strategy to maximize performance, responsiveness, and fairness.
🔁 Process States Recap (only relevant ones)
[ Ready ] ← waiting to be scheduled
↓
[ Running ] ← currently executing
↓
[ Blocked / Waiting ] ← waiting for I/O or sleep
The scheduler makes decisions only among Ready processes.
⚙️ Role of the CPU Scheduler
-
Picks one process from the ready queue
-
Allocates the CPU to it
-
After a while, may preempt and switch to another (depends on the algorithm)
🧩 When is Scheduling Triggered?
| Situation | Trigger |
|---|---|
| 1️⃣ Process exits | Choose next process |
| 2️⃣ Process blocks (I/O, sleep) | Choose next |
| 3️⃣ Time slice expires (in preemptive OS) | Preempt and switch |
| 4️⃣ Higher priority process arrives | Preempt current |
📊 Goals of Scheduling
| Goal | Meaning |
|---|---|
| ⏱️ CPU Utilization | Keep CPU busy as much as possible |
| 🚀 Throughput | Max # of processes completed per time unit |
| 🕰️ Turnaround Time | Time from submission → completion |
| ⌛ Waiting Time | Time spent in ready queue |
| 🧍♂️ Response Time | Time to first response (interactive systems) |
| ⚖️ Fairness | No starvation, all get CPU eventually |
🔀 Common Scheduling Algorithms (Just Names for Now)
| Type | Examples |
|---|---|
| Non-Preemptive | FCFS, SJF (non-preemptive) |
| Preemptive | Round Robin, SRTF, Priority Scheduling, Multilevel Queue |
We’ll cover each one in detail separately if you want.
📦 Example (Round Robin)
Let’s say we have 3 processes:
P1, P2, P3, each gets time quantum = 2ms
Time: | P1 | P2 | P3 | P1 | P2 | ...
↑ ↑ ↑ ↑
Context switches happen here
The CPU is shared in fixed time slices, creating the illusion that all processes are running “at the same time”.
🧠 Interview-Ready Definition:
Process Scheduling is the mechanism by which the OS decides which process in the ready queue gets the CPU next. It uses various algorithms to optimize CPU usage, responsiveness, throughput, and fairness in a multi-process environment.