Process
Process
processes are selected for execution on the CPU. When multiple processes are in the
ready queue (i.e., they are waiting to run), the CPU scheduler selects one of them based
on a scheduling algorithm.
Types of Scheduling:
1. Preemptive Scheduling
The CPU can be taken away from a running process (e.g., Round Robin, SRTF).
2. Non-Preemptive Scheduling
Once a process starts, it runs till completion (e.g., FCFS, SJF).
A scheduler in an operating system is a component that decides which process will run
next on the CPU. Since multiple processes can be ready to run at the same time, the
scheduler plays a crucial role in CPU resource management.
What is a Scheduler?
Speed
Scheduler Type Description Frequency
Requirement
1. Long-Term
Decides which jobs (processes) are
Scheduler (Job Infrequent Slow
admitted into the system for processing
Scheduler)
2. Short-Term
Selects which ready process gets the Very
Scheduler (CPU Very Fast
CPU next Frequent
Scheduler)
1. Long-Term Scheduler
Selects processes from the ready queue and assigns the CPU
3. Medium-Term Scheduler
Used in swapping: temporarily removes (suspends) processes from main memory
and brings them back later
Key Features:
If two processes have the same priority, they are scheduled according to FCFS
(First-Come, First-Served).
Can be:
P1 10 3
P2 1 1
P3 2 4
P4 1 5
Process Burst Time (ms) Priority
P5 5 2
Execution Order:
P2 → P5 → P1 → P3 → P4
(Highest priority = 1)
Gantt Chart:
CopyEdit
| P2 | P5 | P1 | P3 | P4 |
0 1 6 16 18 19
P2 1 1 0
P5 5 2 1
P1 10 3 6
P3 2 4 16
P4 1 5 18
Advantages:
Disadvantages:
Starvation: Low-priority processes may never get executed.
Round Robin (RR) is one of the simplest and most widely used CPU scheduling
algorithms, especially in time-sharing systems. It gives each process a fixed time slot
(quantum) in a cyclic order.
Key Concepts:
Preemptive scheduling
Each process gets the CPU for a time quantum (e.g., 4 ms)
If a process does not finish within its quantum, it is preempted and placed at the
end of the ready queue
Example:
Time Quantum = 4 ms
P1 10
P2 4
P3 5
Gantt Chart:
CopyEdit
| P1 | P2 | P3 | P1 | P3 | P1 |
0 4 8 12 16 17 21
Explanation:
P1 runs for 4 → remaining 6
P1 10 21 21 11
P2 4 8 8 4
P3 5 17 17 12
Advantages:
No starvation
Disadvantages:
Key Tip:
Time Quantum must be carefully chosen: