VOOZH about

URL: https://www.geeksforgeeks.org/dsa/round-robin-scheduling-with-different-arrival-times/

⇱ Round Robin Scheduling Algorithm with Different Arrival Time - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Round Robin Scheduling Algorithm with Different Arrival Time

Last Updated : 11 Jul, 2025

Round Robin Scheduling is one of the most popular CPU scheduling algorithms used in operating systems. This algorithm is designed to handle processes efficiently by assigning a fixed time slice or quantum to each process.

However, when processes arrive at different times, the scheduling becomes slightly more complex but remains true to its principles. In this article, we'll explore how the Round Robin Scheduling Algorithm effectively handles this situation. Also, we'll see its program implementation.

Characteristics of RR Scheduling Algo with Different Arrival Time

  • Handles Dynamic Arrival: Processes can arrive at different times, and the scheduler dynamically adds them to the ready queue as they arrive, ensuring no process is overlooked.
  • Time Quantum Distribution: Each process is allocated a fixed time slice (time quantum) for execution, regardless of its arrival time.
  • Preemptive Execution: If a process doesn’t complete within its time quantum, it is preempted and added back to the queue for its next turn, even if new processes have arrived.
  • Fair Scheduling: Even with different arrival times, all processes are treated fairly, and no process is given priority over others by default.
  • Minimizes Starvation: New processes are regularly added to the queue, and the algorithm ensures that all processes get CPU time, reducing the risk of starvation.
  • Efficient Queue Updates: The ready queue is updated dynamically as new processes arrive, maintaining a circular queue structure for smooth execution.
  • Impact on Turnaround and Waiting Time: Processes arriving later may experience slightly increased waiting times, but the algorithm works to minimize delays by rotating through all tasks.

Example of Round Robin Scheduling Algorithm for the Different Arrival Time:


After all these we get the three times which are:  

  1. Completion Time: the time taken for a process to complete.
  2. Turn Around Time: total time the process exists in the system. (completion time - arrival time).
  3. Waiting Time: total time waiting for their complete execution. (turn around time - burst time ).
  • Turnaround Time (TAT) = Completion Time - Arrival Time.
  • Waiting Time (WT) = TAT - Burst Time.
ProcessArrival TimeBurst TimeCompletion TimeTurnaround Time (TAT)Waiting Time (WT)
P10514149
P217222114
P334181511
P456211610

How to implement in aprogramming language

  1. Declare arrival[], burst[], wait[], turn[] arrays and initialize them. Also declare a timer variable and initialize it to zero. To sustain the original burst array create another array (temp_burst[]) and copy all the values of burst array in it.
  2. To keep a check we create another array of bool type which keeps the record of whether a process is completed or not. we also need to maintain a queue array which contains the process indices (initially the array is filled with 0).
  3. Now we increment the timer variable until the first process arrives and when it does, we add the process index to the queue array.
  4. Now we execute the first process until the time quanta and during that time quanta, we check whether any other process has arrived or not and if it has then we add the index in the queue (by calling the fxn. queueUpdation()).
  5. Now, after doing the above steps if a process has finished, we store its exit time and execute the next process in the queue array. Else, we move the currently executed process at the end of the queue (by calling another fxn. queueMaintainence()) when the time slice expires.
  6. The above steps are then repeated until all the processes have been completely executed. If a scenario arises where there are some processes left but they have not arrived yet, then we shall wait and the CPU will remain idle during this interval.

Below is the implementation of the above approach: 

(For the sake of simplicity, we assume that the arrival times are entered in a sorted way)

Output:

Enter the time quanta : 2
Enter the number of processes : 4
Enter the arrival time of the processes : 0 1 2 3
Enter the burst time of the processes : 5 4 2 1
Program No. Arrival Time Burst Time Wait Time TurnAround Time
1 0 5 7 12
2 1 4 6 10
3 2 2 2 4
4 3 1 5 6
Average wait time : 5
Average Turn Around Time : 8

In case of any queries or a problem with the code, please write it in the comment section.

Note: A slightly optimized version of the above-implemented code could be done by using Queue data structure as follows:

Enter the arrival time and burst time of each process: 
0 5
1 4
2 2
3 1Enter the number of processes: 4
Enter time quantum: 2
Process 1: Waiting Time: 7 Turnaround Time: 12
Process 2: Waiting Time: 6 Turnaround Time: 10
Process 3: Waiting Time: 2 Turnaround Time: 4
Process 4: Waiting Time: 5 Turnaround Time: 6
Average Waiting Time: 5
Average Turnaround Time: 8
Comment
Article Tags:
Article Tags: