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.
Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.
- Difference between Priority Scheduling and Round Robin (RR) CPU scheduling
- Program for Round Robin scheduling | Set 1
- Difference between Shortest Job First (SJF) and Round-Robin (RR) scheduling algorithms
- Difference between Longest Job First (LJF) and Round Robin (RR) scheduling algorithms
- Difference between Multi Level Queue (MLQ) Scheduling and Round Robin (RR) algorithms
- Relation in FCFS and Round Robin Scheduling Algorithm
- Relation between Preemptive Priority and Round Robin Scheduling Algorithm
- Round Robin Scheduling with different arrival times
- Calculate server loads using Round Robin Scheduling
- Priority to Round-robin scheduling with dynamic time quantum
- Difference between First Come First Served (FCFS) and Round Robin (RR) Scheduling Algorithm
- Find the order of execution of given N processes in Round Robin Scheduling
- Multilevel Feedback Queue Scheduling (MLFQ) CPU Scheduling
- Difference between Priority scheduling and Shortest Job First (SJF) CPU scheduling
- Program for FCFS CPU Scheduling | Set 1
- Program for Shortest Job First (or SJF) CPU Scheduling | Set 1 (Non- preemptive)
- CPU Scheduling in Operating Systems
- Operating Systems | CPU Scheduling | Question 1
- Operating Systems | CPU Scheduling | Question 2
- Program for Priority CPU Scheduling | Set 1
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.