Prerequisite – Program for Round Robin scheduling
In the traditional Round Robin scheduling algorithm all processes were treated equally for processing. The objective of the Selfish Round Robin is to give better service to processes that have been executing for a while than to newcomers. Its a more logical and superior implementation compared to the normal Round Robin algorithm.
- Processes in the ready list are partitioned into two lists: NEW and ACCEPTED.
- The New processes wait while Accepted processes are serviced by the Round Robin.
- Priority of a new process increases at rate ‘a’ while the priority of an accepted process increases at rate ‘b’.
- When the priority of a new process reaches the priority of an accepted process, that new process becomes accepted.
- If all accepted processes finish, the highest priority new process is accepted.
Let’s trace out the general working of this algorithm :-
STEP 1 : Assume that initially there are no ready processes, when the first one, A, arrives. It has priority 0 to begin with. Since there are no other accepted processes, A is accepted immediately.
STEP 2 : After a while another process, B, arrives. As long as b / a < 1, B’s priority will eventually catch up to A’s, so it is accepted; now both A and B have the same priority.
STEP 3 : All accepted processes share a common priority (which rises at rate b ); that makes this policy easy to implement i.e any new process’s priority is bound to get accepted at some point. So no process has to experience starvation.
STEP 4 : Even if b / a > 1, A will eventually finish, and then B can be accepted.
Adjusting the parameters a and b : -> If b / a >= 1, a new process is not accepted until all the accepted processes have finished, so SRR becomes FCFS. -> If b / a = 0, all processes are accepted immediately, so SRR becomes RR. -> If 0 < b / a < 1, accepted processes are selfish, but not completely.
Example on Selfish Round Robin –
Solution (where a = 2 and b = 1) –
Process A gets accepted as soon as it comes at time t = 0. So its priority is increased only by ‘b’ i.e ‘1’ after each second. B enters at time t = 1 and goes to the waiting queue. So its priority gets increased by ‘a’ i.e. ‘2’ at time t = 2. At this point priority of A = priority of B = 2.
So now both process A & B are in the accepted queue and are executed in a round robin fashion. At time t = 3 process C enters the waiting queue. At time t = 6 the priority of process C catches up to the priority of process B and then they start executing in a Round Robin manner. When B finishes execution at time t = 10, D is automatically promoted to the accepted queue.
Similarly when D finishes execution at time t = 15, E is automatically promoted to the accepted queue.
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Program for Round Robin scheduling | Set 1
- Round Robin Scheduling with different arrival times
- Difference between Shortest Job First (SJF) and Round-Robin (RR) scheduling algorithms
- Difference between First Come First Served (FCFS) and Round Robin (RR) Scheduling Algorithm
- Multilevel Feedback Queue Scheduling (MLFQ) CPU Scheduling
- Thread Scheduling
- LOOK Disk Scheduling Algorithm
- First Come, First Serve – CPU Scheduling | (Non-preemptive)
- C-LOOK Disk Scheduling Algorithm
- Rate-monotonic scheduling
- Foreground-Background Scheduling
- Fair-share CPU scheduling
- Difference between SJF and LJF CPU scheduling algorithms
- Multilevel Queue (MLQ) CPU Scheduling
- Program for Priority CPU Scheduling | Set 1