Given CPU time slice of 2 ms and the following list of processes. Process Burst time (ms) Arrival time (ms) p 1 3 0 p 2 4 2 p 3 5 5 Find average turnaround time and average waiting time using round-robin CPU scheduling?
5.66, 1.66
Round Robin (RR) is a CPU scheduling algorithm where each process is assigned a fixed time slice (also called quantum) in a cyclic way. It is a preemptive algorithm because the CPU can be taken away from a process even before it completes, if its time slice expires. It is designed for time-sharing systems.
When a process gets the CPU, it runs for at most one time slice. If the process completes within the time slice, it exits the system. If the process requires more CPU time, it is preempted and moved to the end of the ready queue. The scheduler then picks the next process from the front of the ready queue.
Key terms in CPU scheduling:
We are given three processes with their respective burst times and arrival times, and a CPU time slice (quantum) of 2 ms for Round Robin scheduling.
| Process | Burst Time (ms) | Arrival Time (ms) |
|---|---|---|
| p1 | 3 | 0 |
| p2 | 4 | 2 |
| p3 | 5 | 5 |
We need to find the average turnaround time and average waiting time for these processes using the Round Robin algorithm with a time slice of 2 ms.
Let's trace the execution of the processes using a Gantt chart representation and track the ready queue. The time slice is 2 ms.
Gantt Chart:
| p1 (2) | p2 (2) | p1 (1) | p2 (2) | p3 (2) | p3 (2) | p3 (1) |
0 2 4 5 7 9 11 12
Note: Let's re-evaluate the Gantt chart and queue state carefully based on the typical RR implementation where arrival at time t occurs before preemption at time t.
Revised Gantt Chart:
| p1 (2) | p2 (2) | p1 (1) | p2 (2) | p3 (2) | p3 (2) | p3 (1) |
0 2 4 5 7 9 11 12
The Gantt chart appears consistent across both interpretations for this specific scenario regarding arrivals vs. preemption at the same time point. Let's proceed with calculating metrics based on these completion times.
Now we calculate the turnaround time and waiting time for each process.
| Process | Arrival Time (ms) | Burst Time (ms) | Completion Time (ms) | Turnaround Time (ms) (Completion - Arrival) |
Waiting Time (ms) (Turnaround - Burst) |
|---|---|---|---|---|---|
| p1 | 0 | 3 | 5 | 5 - 0 = 5 | 5 - 3 = 2 |
| p2 | 2 | 4 | 7 | 7 - 2 = 5 | 5 - 4 = 1 |
| p3 | 5 | 5 | 12 | 12 - 5 = 7 | 7 - 5 = 2 |
Now, we calculate the average turnaround time and average waiting time.
Total Turnaround Time = Turnaround Time(p1) + Turnaround Time(p2) + Turnaround Time(p3)
Total Turnaround Time = 5 ms + 5 ms + 7 ms = 17 ms
Average Turnaround Time = $\frac{\text{Total Turnaround Time}}{\text{Number of Processes}}$
Average Turnaround Time = $\frac{17}{3} \text{ ms} \approx 5.66 \text{ ms}$
Total Waiting Time = Waiting Time(p1) + Waiting Time(p2) + Waiting Time(p3)
Total Waiting Time = 2 ms + 1 ms + 2 ms = 5 ms
Average Waiting Time = $\frac{\text{Total Waiting Time}}{\text{Number of Processes}}$
Average Waiting Time = $\frac{5}{3} \text{ ms} \approx 1.66 \text{ ms}$
Using Round Robin scheduling with a time slice of 2 ms:
| Metric | Definition | Calculation | Importance |
|---|---|---|---|
| Arrival Time | When a process enters the ready queue. | Given in problem. | Determines when a process is eligible for CPU. |
| Burst Time | Total CPU time needed. | Given in problem. | Intrinsic property of the process. |
| Completion Time | When a process finishes execution. | Determined by scheduling algorithm trace. | Endpoint for calculating other metrics. |
| Turnaround Time | Total time in system. | Completion Time - Arrival Time | Measures total time from submission to completion. |
| Waiting Time | Time spent waiting in the ready queue. | Turnaround Time - Burst Time | Measures time spent idle, waiting for CPU. |
Round Robin scheduling is known for providing fairness among processes by giving each one a turn with the CPU.
Choosing the right time slice is crucial. A large time slice makes RR behave more like First-Come, First-Served (FCFS). A very small time slice increases context switching overhead.
Consider the following four processes with the arrival time and length of CPU burst given in milliseconds :
| Process | Arrival Time | Burst Time |
| P 1 | 0 | 8 |
| P 2 | 1 | 4 |
| P 3 | 2 | 9 |
| P 4 | 3 | 5 |
The average waiting time for preemptive SJF scheduling algorithm is
Consider the following set of processes and the length of CPU burst time given in milliseconds:
Process | CPU Burst time (ms) |
P 1 | 5 |
P 2 | 7 |
P 3 | 6 |
P 4 | 4 |
Assume that processes being scheduled with Round-Robin Scheduling Algorithm with Time Quantum 4ms. Then the waiting time for P 4is _________ ms.
Consider three intensive processes, which requires 10,20 and 30 units of time and arrive at times 0,2 and 6 respectively. how many context switches are needed if the operating system implements a shortest remaining time first scheduling algorithm? Do not count the context switches at time zero and at the end.
Which of the following CPU scheduling algorithms is/are supported by LINUX operating system?
In which of the following scheduling criteria, context switching will never take place?