CPU & Disk Scheduling, Memory Allocation - OS Concepts
FCFS (First Come First Serve)
- Non-preemptive scheduling: executes processes in the order they arrive.
- Simple but may lead to high waiting time if long processes arrive first.
SJF (Shortest Job First)
- Selects process with the smallest burst time.
- Can be preemptive or non-preemptive.
- Efficient but may cause starvation of longer processes.
Disk Scheduling Algorithms
1. FCFS - Serve requests in arrival order.
2. SSTF - Choose the request closest to current head.
3. SCAN - Head moves to end then reverses (like elevator).
4. LOOK - Like SCAN but only goes to last request before reversing.
5. C-SCAN - Head moves in one direction and jumps to beginning.
6. C-LOOK - Like C-SCAN but only up to last request.
7. FSCAN - Divides queue and processes one batch at a time.
Memory Allocation Algorithms
1. First Fit:
- Allocates the first available block large enough for the process.
- Fast but may leave fragmentation.
2. Best Fit:
- Allocates the smallest sufficient block.
- Reduces leftover space but may be slower.
Time Terms in CPU Scheduling
- Arrival Time (AT): When process enters ready queue.
- Completion Time (CT): When process finishes execution.
- Turnaround Time (TAT): TAT = CT - AT
- Waiting Time (WT): WT = TAT - Burst Time (BT)
Example:
Processes: P1(AT=0, BT=5), P2(AT=1, BT=3), P3(AT=2, BT=4)
FCFS Execution: P1 (0-5), P2 (5-8), P3 (8-12)
CT: P1=5, P2=8, P3=12
TAT: P1=5, P2=7, P3=10
WT: P1=0, P2=4, P3=6