To demonstrate the working of different scheduling algorithms using the given input, we'll consider the following scenarios: First Come First Served (FCFS), Priority Scheduling (PS), and Round Robin (RR) with a quantum time of 3 seconds.
Input Data:
| Process ID | Priority | Arrival Time (sec) | Execution Time (sec) |
|---|
| P0 | 2 | 0 | 12 |
| P1 | 0 | 1 | 5 |
| P2 | 3 | 2 | 8 |
| P3 | 1 | 3 | 4 |
First Come First Served (FCFS)
In FCFS, processes are executed in the order they arrive.
-
P0 arrives at 0 sec and executes for 12 sec.
- Completion Time: 12 sec
- Turnaround Time: 12 sec
- Wait Time: 0 sec
-
P1 arrives at 1 sec but starts at 12 sec and executes for 5 sec.
- Completion Time: 17 sec
- Turnaround Time: 16 sec
- Wait Time: 11 sec
-
P2 arrives at 2 sec but starts at 17 sec and executes for 8 sec.
- Completion Time: 25 sec
- Turnaround Time: 23 sec
- Wait Time: 15 sec
-
P3 arrives at 3 sec but starts at 25 sec and executes for 4 sec.
- Completion Time: 29 sec
- Turnaround Time: 26 sec
- Wait Time: 22 sec
Priority Scheduling (PS)
In Priority Scheduling, processes are executed based on their priority (lower number means higher priority).
-
P1 (Priority 0) arrives at 1 sec and executes for 5 sec.
- Completion Time: 6 sec
- Turnaround Time: 5 sec
- Wait Time: 0 sec
-
P3 (Priority 1) arrives at 3 sec but starts at 6 sec and executes for 4 sec.
- Completion Time: 10 sec
- Turnaround Time: 7 sec
- Wait Time: 3 sec
-
P0 (Priority 2) arrives at 0 sec but starts at 10 sec and executes for 12 sec.
- Completion Time: 22 sec
- Turnaround Time: 22 sec
- Wait Time: 10 sec
-
P2 (Priority 3) arrives at 2 sec but starts at 22 sec and executes for 8 sec.
- Completion Time: 30 sec
- Turnaround Time: 28 sec
- Wait Time: 20 sec
Round Robin (RR) with Quantum Time of 3 sec
In Round Robin, each process gets a fixed time slice (quantum) to execute.
-
P0 starts at 0 sec and executes for 3 sec.
-
P1 starts at 3 sec and executes for 3 sec.
-
P2 starts at 6 sec and executes for 3 sec.
-
P3 starts at 9 sec and executes for 3 sec.
-
P0 resumes at 12 sec and executes for 3 sec.
-
P1 resumes at 15 sec and executes for 2 sec.
- Completion Time: 17 sec
- Turnaround Time: 16 sec
- Wait Time: 14 sec
-
P2 resumes at 17 sec and executes for 3 sec.
-
P3 resumes at 20 sec and executes for 1 sec.
- Completion Time: 21 sec
- Turnaround Time: 18 sec
- Wait Time: 17 sec
-
P0 resumes at 21 sec and executes for 3 sec.
-
P2 resumes at 24 sec and executes for 2 sec.
- Completion Time: 26 sec
- Turnaround Time: 24 sec
- Wait Time: 18 sec
-
P0 resumes at 26 sec and executes for 3 sec.
- Completion Time: 29 sec
- Turnaround Time: 29 sec
- Wait Time: 17 sec
Summary
FCFS:
| Process ID | Completion Time | Turnaround Time | Wait Time |
|---|
| P0 | 12 sec | 12 sec | 0 sec |
| P1 | 17 sec | 16 sec | 11 sec |
| P2 | 25 sec | 23 sec | 15 sec |
| P3 | 29 sec | 26 sec | 22 sec |
Priority Scheduling:
| Process ID | Completion Time | Turnaround Time | Wait Time |
|---|
| P1 | 6 sec | 5 sec | 0 sec |
| P3 | 10 sec | 7 sec | 3 sec |
| P0 | 22 sec | 22 sec | 10 sec |
| P2 | 30 sec | 28 sec | 20 sec |
Round Robin:
| Process ID | Completion Time | Turnaround Time | Wait Time |
|---|
| P0 | 29 sec | 29 sec | 17 sec |
| P1 | 17 sec | 16 sec | 14 sec |
| P2 | 26 sec | 24 sec | 18 sec |
| P3 | 21 sec | 18 sec | 17 sec |
This demonstrates the working of FCFS, Priority Scheduling, and Round Robin scheduling algorithms with the given input data.