Function Signature
Description
Implements the Round Robin scheduling algorithm with time quantum. Each process is allocated a fixed time slice (quantum) for execution. If a process doesn’t complete within its quantum, it’s moved to the end of the ready queue, allowing other processes to execute. This ensures fair CPU time distribution among all processes.Parameters
Array of arrival times for each process. Each element represents when a process arrives in the system.
Array of CPU burst times for each process. Each element represents total time a process needs to execute.
Time quantum (time slice) allocated to each process per execution cycle. Determines how long each process runs before switching.
Return Value
Returns an object containing scheduling metrics:Array of start times for each process (indexed by process ID). Records when process first began execution.
Array of completion times for each process (indexed by process ID).
Array of waiting times for each process. Calculated as:
turnaround_time - cpu_time.Array of turnaround times for each process. Calculated as:
completion_time - arrival_time. Represents total time from arrival to completion.Total time required to complete all processes (maximum completion time).
Example Usage
Sample Output
Output Explanation
With quantum = 2, execution proceeds as follows:- Time 0-2: Process 0 runs (remaining: 3)
- Time 2-4: Process 1 runs (remaining: 1)
- Time 4-6: Process 2 runs (remaining: 6)
- Time 6-8: Process 3 runs (remaining: 4)
- Time 8-10: Process 0 runs (remaining: 1)
- Time 10-12: Process 1 runs (completes)
- And so on…
Algorithm Details
How It Works
- Maintain a ready queue of processes
- Add newly arrived processes to the queue
- Take the first process from queue
- Execute it for one quantum or until completion (whichever is shorter)
- Check for new arrivals after each time unit during execution
- If process not complete, add it back to end of queue
- Repeat until all processes complete
Complexity
- Time Complexity: O(n × t) where t is total execution time
- Space Complexity: O(n) for process data and ready queue
Characteristics
- Preemptive: Processes are interrupted after each quantum
- Fair: All processes get equal CPU time slices
- Time-sharing: Ideal for interactive systems
- Context Switching: Frequent switches can add overhead
- Quantum Selection:
- Small quantum: More responsive but higher overhead
- Large quantum: Approaches FIFO behavior
- Typical range: 10-100 milliseconds in real systems
Queue Management
The implementation carefully handles:- Adding processes as they arrive during execution
- Preventing duplicate queue entries with
enColaflag - Checking for arrivals after each time unit, not just at quantum boundaries