Process States in OS
Introduction
An OS manages processes like a conductor leading an orchestra. Processes change states (e.g., running, waiting), and schedulers decide when and how they transition. Let’s break down process states and the three key schedulers: Long-Term, Short-Term, and Medium-Term.
What is a Process?
A process is a program in execution. For example:
- The recipe (program) → Cooking (process)
- The OS tracks processes using states and schedulers.
The 5 Core Process States
- New: Being created.
- Ready: Waiting for CPU time.
- Running: Executing on the CPU.
- Waiting/Blocked: Paused (needs I/O or event).
- Terminated: Finished or killed.
Schedulers: The OS’s Traffic Controllers
Schedulers decide which process runs next and how resources are allocated. There are three types:
1. Long-Term Scheduler (LTS) – The “Gatekeeper”
Purpose
- Also called the Job Scheduler.
- Decides which processes enter the Ready state from the pool of new processes.
- Controls the degree of multiprogramming (how many processes stay in memory).
Analogy
A club bouncer deciding who gets inside to join the party.
Interaction with Process States
- Moves processes from New → Ready.
- Prioritizes critical processes (e.g., system tasks over user apps).
Example
When you start your computer, the LTS loads essential system processes (e.g., antivirus, drivers) into memory first.
2. Short-Term Scheduler (STS) – The “Speed Manager”
Purpose
- Also called the CPU Scheduler.
- Picks a process from the Ready queue to run on the CPU.
- Runs frequently (every few milliseconds) for fast switching.
Analogy
A chef deciding which prepped dish to cook next.
Interaction with Process States
- Moves processes from Ready → Running.
- Uses algorithms like Round Robin, Priority Scheduling, etc.
Example
You’re running Chrome, Word, and Spotify. The STS rapidly switches the CPU between them, making it feel simultaneous.
3. Medium-Term Scheduler (MTS) – The “Memory Optimizer”
Purpose
- Also called the Swapping Scheduler.
- Temporarily removes processes from memory (swaps out) to free resources.
- Later brings them back (swaps in) when memory is free.
Analogy
A warehouse manager moving less-used items to storage to free up shelf space.
Interaction with Process States
- Swaps out: Ready/Waiting → Suspended (moved to disk).
- Swaps in: Suspended → Ready.
Example
Your game is paused and swapped to disk when you switch to a browser. The MTS reloads it when you return.
How Schedulers Work Together
[New Processes]
↓
LTS → [Ready Queue]
↓
STS → [Running]
↓
(Pause/I/O) → [Waiting]
↓
(Time up) → [Ready]
↓
[Terminated]
↑
MTS swaps ↔ [Suspended (Disk)]
Schedulers & Process States: A Table
Scheduler | Frequency | Role | Key Impact |
---|---|---|---|
Long-Term (LTS) | Infrequent | Admits processes to memory | Controls system load |
Short-Term (STS) | Very frequent | Assigns CPU to Ready processes | Affects responsiveness |
Medium-Term (MTS) | Occasional | Swaps processes in/out of memory | Balances memory usage |
Why Schedulers Matter
- LTS: Prevents memory overload by limiting active processes.
- STS: Ensures fair CPU time and quick response (e.g., smooth multitasking).
- MTS: Avoids crashes by freeing memory when overloaded.
Real-World Example: Editing a Video
- LTS: Admits your video editor and background apps to memory.
- STS: Lets the editor use the CPU to render frames.
- MTS: Swaps out Spotify (while idle) to free memory for rendering.
- STS: Pauses the editor when it waits for user input (→ Waiting state).
- MTS: Swaps the editor back in when you resume work.
FAQ’s
Q: Can the STS skip the Ready queue?
No! Only processes in the Ready state are eligible for the CPU.
Q: Why isn’t the LTS used in modern OS?
Most desktop OS (Windows, Linux) use direct execution: all processes are admitted immediately (no LTS). LTS is still used in batch systems (e.g., servers).
Q: What happens if the MTS swaps out a Running process?
It can’t! The MTS only swaps out Ready or Waiting processes.
Q: Which scheduler has the biggest impact on performance?
The STS! Poor algorithms (e.g., FIFO) can cause lag.
Advanced: Two-State vs Seven-State Models
- Two-State: Simple (Running/Not Running).
- Seven-State: Adds Suspended Ready, Suspended Waiting, etc. for swapping.
Summary
Process states and schedulers are the OS’s secret sauce:
- LTS: Decides who joins the party.
- STS: Keeps the party lively.
- MTS: Manages the crowd when it’s too packed.