This is a multipart blog article series, and in this series I am going to explain you the concepts of operating system. This article series is divided into multiple modules and this is the second module which consists of 11 articles.
Round robin is one of the most famous CPU scheduling algorithm. We will see a question on it and try to understand the concepts of round robin CPU scheduling in an operating system.
Round robin scheduling
- Criteria of round robin is time quantum.
- Mode of round robin scheduling is pre-emptive.
| Process No. | Arrival time | Burst time | Completion time | Turnaround time | Waiting time | Response time |
|---|---|---|---|---|---|---|
| P1 | 0 | 5 | ||||
| P2 | 1 | 4 | ||||
| P3 | 2 | 2 | ||||
| P4 | 4 | 1 |
Given time quantum = 2 unit of time
Before solving this question let’s see some points, which will help to solve this question.
- In round robin context switching is done.
- Context switching means to save the context of a running process. Context means PCB (process complete block), and sending back the process to ready queue and start executing next process, we save the context because we do not want to execute it from beginning rather we want to start executing that process from where we left.
- At time unit 0 process
P1arrives to CPU start executingP1, till2unit of time because the time quantum given in the question is2.
-
P2process arrives at1time unit so it was present in the ready queue, so whenP1get preempt then P2’s execution start. -
P2execute for2time unit and then it will also get preempt.
- Process
P3has arrived at time unit2, all the processes are arrived in the ready queue. -
P3will also get executed for2unit of time, and then got terminated as its burst time was also2time unit.
- Now,
P1was in ready queue beforeP4that’s why we will executeP1for2time unit and then it will get pre-empted.
-
P4will execute for1time unit because its burst time is only1, and get terminated.
- Now
P2will execute for2time unit and after2time unit it will get terminated; now onlyP1is in the ready queue.
-
P1will get executed for1time unit and then get terminated. - Six time context switching happened while calculating. We do not count first and last (which is 0 and 12 in our case.)
All the process got completely executed. Now we will complete the table, but for it you need to know some formulas.
- Completion time: The time at which process completes its execution.
-
Turnaround time =
Completion time – arrival time -
Waiting time =
turnaround time – burst time -
Response time =
CPU first time allocated – Arrival time
So, the final table obtained will be.
| Process No. | Arrival time | Burst time | Completion time | Turnaround time | Waiting time | Response time |
|---|---|---|---|---|---|---|
| P1 | 0 | 5 | 12 | 12 | 7 | 0 |
| P2 | 1 | 4 | 11 | 10 | 6 | 1 |
| P3 | 2 | 2 | 6 | 4 | 2 | 2 |
| P4 | 4 | 1 | 9 | 5 | 4 | 4 |
So, this was all about Round Robin CPU scheduling. Hope you like it and learned something new from it.
If you have any doubt, question, queries related to this topic or just want to share something with me, then please feel free to contact me.
📱 Contact Me
Twitter
LinkedIn
Telegram
Instagram







Top comments (1)
Can you please brief that when are we supposed to do Context Switching?