VOOZH about

URL: https://www.geeksforgeeks.org/operating-systems/program-for-round-robin-scheduling-for-the-same-arrival-time/

⇱ Program for Round Robin Scheduling for the Same Arrival Time - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Program for Round Robin Scheduling for the Same Arrival Time

Last Updated : 23 Jul, 2025

Round Robin is a CPU scheduling algorithm where each process is cyclically assigned a fixed time slot. It is the preemptive version of the First come First Serve CPU Scheduling algorithm. 

This article focuses on implementing a Round Robin Scheduling Program where all processes have the same arrival time. In this scenario, all processes arrive at the same time which makes scheduling easier. You can focus on the main logic of dividing CPU time equally and managing the process queue.

Characteristics of Round Robin CPU Scheduling Algorithm with Same Arrival Time

Below are the key characteristics of the Round Robin Scheduling Algorithm when all processes share the same arrival time:

  1. Equal Time Allocation: Each process gets an equal and fixed time slice (time quantum) to execute, ensuring fairness.
  2. Cyclic Execution: Processes are scheduled in a circular order, and the CPU moves to the next process in the queue after completing the time quantum.
  3. No Process Starvation: All processes are guaranteed CPU time at regular intervals, preventing any process from being neglected.
  4. Same Start Time: Since all processes arrive at the same time, there is no need to consider arrival time while scheduling, simplifying the process.
  5. Context Switching: Frequent context switching occurs as the CPU moves between processes after each time quantum, which can slightly impact performance.

Example of Round Robin Scheduling Algorithm for the Same Arrival Time


How to Compute Below Times in Round Robin Using a Program?

  • Completion Time: Time at which process completes its execution.
  • Turn Around Time: Time Difference between completion time and arrival time. Turn Around Time = Completion Time - Arrival Time
  • Waiting Time(W.T): Time Difference between turn around time and burst time. 
    Waiting Time = Turn Around Time - Burst Time
ProcessCompletion TimeTurnaround Time (CT - AT)Waiting Time (TAT - BT)
P1171710
P213139
P3202011

Program for Round Robin Scheduling with Arrival Time as 0 for all Processes

Steps to find waiting times of all processes

  • Create an array rem_bt[] to keep track of remaining burst time of processes. This array is initially a copy of bt[] (burst times array)
  • Create another array wt[] to store waiting times of processes. Initialize this array as 0.
  • Initialize time : t = 0
  • Keep traversing all the processes while they are not done. Do following for i'th process if it is not done yet.
    • If rem_bt[i] > quantum
      • t = t + quantum
      • rem_bt[i] -= quantum;
    • Else // Last cycle for this process
      • t = t + rem_bt[i];
      • wt[i] = t - bt[i]
      • rem_bt[i] = 0; // This process is over

Once we have waiting times, we can compute turn around time tat[i] of a process as sum of waiting and burst times, i.e., wt[i] + bt[i].
Below is implementation of above steps. 


Output
PN BT WT TAT
 1 10 13 23
 2 5 10 15
 3 8 13 21
Average waiting time = 12
Average turn around time = 19.6667

Next Article to Read: Program for Round Robin Scheduling with Different Arrival Times for all Processes

Conclusion

In conclusion, Round Robin CPU scheduling is a fair and preemptive algorithm that allocates a fixed time quantum to each process, ensuring equal CPU access. It is simple to implement but can lead to higher context-switching overhead. While it promotes fairness and prevents starvation, it may result in longer waiting times and reduced throughput, depending on the time quantum. Effective program implementation allows for the calculation of key metrics like completion time, turnaround time, and waiting time, aiding in performance evaluation and optimization. 

Comment
Article Tags: