I'll demonstrate the working of three common data structures/algorithms for process scheduling: First-Come-First-Served (FCFS), Priority Scheduling (PS), and Round Robin (RR), using the provided input. Note that the Wait Time and Turnaround Time are typically output metrics, calculated after the scheduling process, so I'll compute these as we go through each scenario. Completion Time will also be determined for each process in each scenario.
1. First-Come-First-Served (FCFS)
Input:
| Process ID | Priority | Arrival Time (sec) | Execution Time (milli sec) |
|---|
| P0 | 2 | 0 | 12000 |
| P1 | 0 | 1 | 5000 |
| P2 | 3 | 2 | 8000 |
| P3 | 1 | 3 | 4000 |
FCFS Scheduling (Assuming processes are executed in the order of their arrival):
-
P0 Arrives at 0 sec, Starts at 0 sec
- Completion Time: 12 sec (0 sec + 12 sec)
- Turnaround Time: 12 sec
- Wait Time: 0 sec
-
P1 Arrives at 1 sec, but Starts after P0 at 12 sec
- Completion Time: 17 sec (12 sec + 5 sec)
- Turnaround Time: 16 sec
- Wait Time: 11 sec (12 sec - 1 sec)
-
P2 Arrives at 2 sec, but Starts after P1 at 17 sec
- Completion Time: 25 sec (17 sec + 8 sec)
- Turnaround Time: 23 sec
- Wait Time: 15 sec (17 sec - 2 sec)
-
P3 Arrives at 3 sec, but Starts after P2 at 25 sec
- Completion Time: 29 sec (25 sec + 4 sec)
- Turnaround Time: 26 sec
- Wait Time: 22 sec (25 sec - 3 sec)
FCFS Output:
| Process ID | Wait Time | Turnaround Time | Completion Time |
|---|
| P0 | 0 sec | 12 sec | 12 sec |
| P1 | 11 sec | 16 sec | 17 sec |
| P2 | 15 sec | 23 sec | 25 sec |
| P3 | 22 sec | 26 sec | 29 sec |
2. Priority Scheduling (PS) - Non-Preemptive
Note: Lower Priority Value means Higher Priority.
PS Scheduling:
-
P2 (Highest Priority) Starts at 2 sec (after arrival, assuming no preemption)
- Completion Time: 10 sec (2 sec + 8 sec)
- Turnaround Time: 8 sec
- Wait Time: 0 sec (for P2, as it starts immediately after arrival, considering the scenario)
-
P3 (Next in Priority) Starts after P2 at 10 sec
- Completion Time: 14 sec (10 sec + 4 sec)
- Turnaround Time: 11 sec
- Wait Time: 7 sec (10 sec - 3 sec)
-
P0 (Next in Priority) Starts after P3 at 14 sec
- Completion Time: 26 sec (14 sec + 12 sec)
- Turnaround Time: 26 sec
- Wait Time: 14 sec (14 sec - 0 sec)
-
P1 (Lowest Priority) Starts after P0 at 26 sec
- Completion Time: 31 sec (26 sec + 5 sec)
- Turnaround Time: 30 sec
- Wait Time: 25 sec (26 sec - 1 sec)
PS Output:
| Process ID | Wait Time | Turnaround Time | Completion Time |
|---|
| P2 | 0 sec | 8 sec | 10 sec |
| P3 | 7 sec | 11 sec | 14 sec |
| P0 | 14 sec | 26 sec | 26 sec |
| P1 | 25 sec | 30 sec | 31 sec |
3. Round Robin (RR) with Quantum Time = 3 sec
RR Scheduling:
- Processes are executed in a circular manner, with each process getting a time slice (quantum) of 3 sec.
| Process ID | Arrival | Execution Time | Quantum Used | Completion Time | Turnaround Time | Wait Time |
|---|
| | | | | | |
| Initial | | | | | | |
| P0 | 0 sec | 12000 ms = 12s | | | | |
| P1 | 1 sec | 5000 ms = 5s | | | | |
| P2 | 2 sec | 8000 ms = 8s | | | | |
| P3 | 3 sec | 4000 ms = 4s | | | | |
Detailed RR Steps:
-
First Round (0-3 sec):
- P0: 3 sec (0-3 sec, Remaining: 9 sec)
- Wait for P1, P2, P3 to arrive
-
Second Round (3-6 sec, after all have arrived):
- P1: 3 sec (3-6 sec, Remaining: 2 sec)
- P2: 3 sec (6-9 sec, Remaining: 5 sec)
- P0: 3 sec (9-12 sec, Remaining: 6 sec)
- P3: 3 sec (12-15 sec, Remaining: 1 sec)
-
Third Round (15-18 sec):
- P1: 2 sec (15-17 sec, Completed)
- P2: 3 sec (17-20 sec, Remaining: 2 sec)
- P0: 3 sec (20-23 sec, Remaining: 3 sec)
- P3: 1 sec (23-24 sec, Completed)
-
Fourth Round (24-27 sec):
- P2: 2 sec (24-26 sec, Remaining: 0 sec, Completed)
- P0: 3 sec (26-29 sec, Remaining: 0 sec, Completed)
RR Output:
| Process ID | Wait Time | Turnaround Time | Completion Time |
|---|
| P0 | 14 sec | 29 sec | 29 sec |
| P1 | 12 sec | 17 sec | 17 sec |
| P2 | 18 sec | 26 sec | 26 sec |
| P3 | 20 sec | 24 sec | 24 sec |
Note: The quantum time of 3 sec significantly affects the scheduling in Round Robin. Each process executes for 3 sec before the next process is scheduled, allowing for time-sharing and improving responsiveness. This algorithm is particularly useful in systems requiring fairness and preventing any single process from monopolizing the CPU.
Clarification: In the Round Robin scenario, the quantum time determines how long each process runs before being interrupted and placed at the end of the ready queue. This ensures that all processes receive a fair share of CPU time, making it suitable for interactive or time-sharing systems. The provided step-by-step breakdown illustrates how each process is executed in rounds, with the quantum time controlling the duration of each execution slice.