Round-Robin Scheduling


This is another technique to execute processes in CPU. This is the last technique but not the least. I will give you all a very clear understanding of this with the help of a numerical and at the end I will give you the code to implement Round-Robin Scheduling. So, let's get started, shall we?

In Round-Robin Scheduling each process executes for some time quantum(time slice) in a cyclic manner. This scheduling technique is same as FCFS but the only difference is that each process is executed for equal time quantum.

Characteristics of Round-Robin Scheduling

  • It is a preemptive scheduling algorithm.
  • In this CPU executes a process for some time quantum and then moves to a new process.
  • Time slice should be minimal in order to improve efficiency, however it might also differ from OS to OS.
  • It is one of the oldest scheduling techniques.
Numerical:

Schedule the processes given in the picture below according to Round-Robin Scheduling where time slice is of 4ms. Draw a gantt chart. Also find waiting and turn around time for each process.

Round-Robin Scheduling

We will consider a table T which will help us determine remaining time for each process.

1. At arrival time 0 process P1 comes into ready queue. It will be executed for 4ms because time slice is of 4ms. Now, remaining time for P1 is 4ms and we will place this process in table T.
2. At arrival time 4 we have 3 processes to be executed. We will execute P2 for 4ms because time slice is of 4ms. Now, remaining time for P2 is 0 so we won't push it into table T.
3. Then P3 will be executed for 4ms. After execution, P3 has 5ms remaining time so we will place P3 into table T.
4. Then P4 will be executed for 4ms. After execution, P4 has 1ms remaining time so we will place P4 into table T.
5. Now, there are no new processes so we will execute the processes present in table T sequentially.
6. In table T we have P1 with remaining time 4ms, P3 with remaining time 5ms, P4 with remaining time 1ms.
7. P1 will be executed for 4ms. After execution, P1 has remaining time 0ms so it has executed completely.
8. Now we will execute P3 for 4ms. After execution, P3 has remaining time 1ms so it will be pushed into table T again.
9. Next, P4 will be executed for 4ms. But P4 require only 1ms so it will execute for 1ms only. After execution, P4 has remaining time 0ms hence it has also completed execution.
10. Only, one process remaining which is P3. So, P3 will be executed for 1ms.

Gantt Chart:   


Round-Robin Scheduling

Waiting Time for each process

Waiting time is computed by the formula starting execution time - arrival time of a process.
Process                                  Starting execution time - arrival time                          Waiting time
P1                                                          20 - 8                                                                12
P2                                                            7 - 4                                                                  3
P3                                                          24 - 9                                                                15
P4                                                          22 - 5                                                                17

Turn around Time for each Process

Turn around time is computed by the formula completion time - arrival time of a process.
Process                                  Completion time - arrival time                          Waiting time
P1                                                          20 - 0                                                                20
P2                                                            8 - 1                                                                  7
P3                                                          26 - 2                                                                24
P4                                                          25 - 3                                                                22

Implementation in C++


OUTPUT:

Round-Robin Scheduling


Post a Comment (0)
Previous Post Next Post