🧠 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?

SituationTrigger
1️⃣ Process exitsChoose next process
2️⃣ Process blocks (I/O, sleep)Choose next
3️⃣ Time slice expires (in preemptive OS)Preempt and switch
4️⃣ Higher priority process arrivesPreempt current

📊 Goals of Scheduling

GoalMeaning
⏱️ CPU UtilizationKeep CPU busy as much as possible
🚀 ThroughputMax # of processes completed per time unit
🕰️ Turnaround TimeTime from submission → completion
Waiting TimeTime spent in ready queue
🧍‍♂️ Response TimeTime to first response (interactive systems)
⚖️ FairnessNo starvation, all get CPU eventually

🔀 Common Scheduling Algorithms (Just Names for Now)

TypeExamples
Non-PreemptiveFCFS, SJF (non-preemptive)
PreemptiveRound 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.