CPU Scheduling Algorithms
CPU Scheduling Algorithms
#### Overview:
- **First-Come, First-Served (FCFS)** is the simplest CPU scheduling algorithm.
- It is a **non-preemptive** scheduling algorithm, meaning once a process starts
executing, it cannot be interrupted until it completes.
- Processes are executed in the order of their arrival in the ready queue.
#### Characteristics:
1. **Queue-based:** Processes are maintained in a FIFO (First In, First Out) queue.
2. **Fair but Inefficient:** All processes are treated equally based on arrival
time, but it may lead to poor CPU utilization.
#### Advantages:
- Simple to implement.
- Easy to understand.
- No complex decision-making required during execution.
#### Disadvantages:
- **Convoy Effect:** Short processes get stuck waiting behind long processes.
- Not suitable for interactive systems.
- Poor average waiting time for a mix of short and long processes.
#### Example:
| Process | Arrival Time | Burst Time | Execution Order | Completion Time |
Turnaround Time | Waiting Time |
|---------|--------------|------------|-----------------|-----------------|--------
---------|--------------|
| P1 | 0 | 4 | 1 | 4 | 4
| 0 |
| P2 | 1 | 3 | 2 | 7 | 6
| 3 |
| P3 | 2 | 2 | 3 | 9 | 7
| 5 |
#### Formulas:
- **Turnaround Time (TAT):** Completion Time - Arrival Time
- **Waiting Time (WT):** Turnaround Time - Burst Time
---
#### Overview:
- **Round Robin (RR)** is a **preemptive** scheduling algorithm.
- Each process is assigned a fixed **time quantum** (or time slice) during which it
can execute.
- After the time quantum expires, the process is moved to the end of the ready
queue, and the next process gets CPU time.
#### Characteristics:
1. **Time-sharing system:** Ideal for time-sharing and interactive systems.
2. **Fair allocation:** Ensures all processes get equal CPU time in cycles.
3. **Context Switching:** Frequent context switching can impact performance.
#### Advantages:
- Suitable for systems where response time is crucial.
- Prevents long processes from blocking shorter ones.
- Ensures fair allocation of CPU time.
#### Disadvantages:
- Context-switching overhead is high.
- Poor performance if the time quantum is not chosen carefully:
- Too small: High context-switching overhead.
- Too large: Behaves like FCFS.
#### Example:
| Process | Arrival Time | Burst Time | Time Quantum = 2 |
|---------|--------------|------------|-------------------|
| P1 | 0 | 5 | Executes: [0-2], [4-6], [8-9] |
| P2 | 1 | 3 | Executes: [2-4], [6-7] |
| P3 | 2 | 2 | Executes: [7-8] |
#### Formulas:
- **Turnaround Time (TAT):** Completion Time - Arrival Time
- **Waiting Time (WT):** Turnaround Time - Burst Time
---