The Wayback Machine - https://web.archive.org/web/20241001063433/https://www.geeksforgeeks.org/selfish-round-robin-cpu-scheduling/
Open In App

Selfish Round Robin CPU Scheduling

Last Updated : 28 Jan, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

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. It’s a more logical and superior implementation compared to the normal Round Robin algorithm. 

What is the Selfish Round Robin scheduling algorithm?
The Selfish Round Robin (SRR) scheduling algorithm is a modification of the traditional Round Robin algorithm. The objective of SRR is to give better service to processes that have been executing for a while than to newcomers. In SRR, 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. The priority of a new process increases at the rate ‘a’ while the priority of an accepted process increases at the rate ‘b’.

How does SRR scheduling ensure fairness among processes?
A: SRR scheduling ensures fairness among processes by providing each process with an equal amount of CPU time. This is achieved by using a Round Robin approach, where each process is given a time quantum to execute. Once a process completes its time quantum, it is placed at the end of the queue, and the next process is given a chance to execute.

Is SRR scheduling suitable for real-time systems?
A: No, SRR scheduling is not suitable for real-time systems that require strict timing constraints. In such systems, it is essential to ensure that high-priority processes receive CPU time when they need it, which is not possible with SRR scheduling.

Implementation: 

  • 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 = 1, 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 – 

1

Solution (where a = 2 and b = 1) – 

2

Explanation:

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 processes 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.

Advantages:

  1. Fairness: SRR scheduling ensures fairness among all processes by providing each process with an equal amount of CPU time. This makes it a fairer scheduling algorithm than some other algorithms that prioritize certain processes over others.
  2. Efficient CPU utilization: SRR scheduling ensures efficient CPU utilization by allowing processes to use only the CPU time they need. This reduces the likelihood of processes being blocked unnecessarily, which can increase overall system throughput.
  3. Low overhead: SRR scheduling is a simple algorithm that requires little overhead to implement. It is easy to understand and implement, making it a good choice for simple systems.

Disadvantages:

  1. Selfishness: One of the main disadvantages of SRR scheduling is that it allows processes to be selfish and use all their allotted CPU time, even if they do not need it. This can lead to a situation where some processes hoard CPU time, leading to reduced system performance.
  2. Poor response time: SRR scheduling can lead to poor response time for interactive processes that require quick user input. This is because these processes may be forced to wait for their quantum of CPU time, even if they only need a small amount of CPU time.
  3. Poor priority handling: SRR scheduling does not handle process priorities well. All processes are treated equally, regardless of their priority, which can lead to situations where high-priority processes are starved of CPU time.
  4. Inefficient for real-time systems: SRR scheduling is not suitable for real-time systems that require strict timing constraints. In such systems, it is essential to ensure that high-priority processes receive CPU time when they need it, which is not possible with SRR scheduling.


Similar Reads

Difference between Priority Scheduling and Round Robin (RR) CPU scheduling
1. Priority Scheduling Algorithm : Priority scheduling algorithm executes the processes depending upon their priority. Each process is allocated a priority and the process with the highest priority is executed first. Priorities can be defined internally as well as externally. Internal priorities are decided by the system depending upon the number o
3 min read
Difference between First Come First Served (FCFS) and Round Robin (RR) Scheduling Algorithm
First Come First Served Scheduling Algorithm: First Come First Served (FCFS) is the simplest and non-preemptive scheduling algorithm. In First Come First Served (FCFS), the process is allocated to the CPU in the order of their arrival. A queue data structure is used to implement the FCFS scheduling algorithm. The process which is at the head of the
2 min read
Difference between Shortest Job First (SJF) and Round-Robin (RR) scheduling algorithms
1.Shortest Job First (SJF) : Shortest Job First (SJF) Scheduling Algorithm is based upon the burst time of the process. The processes are put into the ready queue based on their burst times. In this algorithm, the process with the least burst time is processed first. The burst time of only those processes is compared that are present or have arrive
3 min read
Difference between Longest Job First (LJF) and Round Robin (RR) scheduling algorithms
1. Longest Job First (LJF) : Longest Job First (LJF) is based upon the burst time of the process. The processes are put into the ready queue based on their burst times. In this algorithm, the process with the largest burst time is processed first. The burst time of only those processes is compared that are present or have arrived until that time. I
3 min read
Difference between Multi Level Queue (MLQ) Scheduling and Round Robin (RR) algorithms
1. Multi Level Queue Scheduling (MLQ) : It is quite difficult to have just one queue and schedule all the processes. This is where multi-level queue scheduling is used. In this the processes are divided into various classes depending upon the property of the processes such as system process, I/O process, etc. Thus we get 'n' number of queues for n
3 min read
Relation in FCFS and Round Robin Scheduling Algorithm
In this article, we'll see how FCFS is special kind of Round Robin Algorithm and Round Robin is special kind of FCFS Algorithm. Also, we will cover the relation with each other. Let's discuss one by one. First Come First Serve (FCFS) Scheduling Algorithm : FCFS is simplest of CPU Scheduling Algorithm which executes process that comes first. It is n
3 min read
Relation between Preemptive Priority and Round Robin Scheduling Algorithm
In this article, we'll try to establish the relation between Round Robin and Preemptive Priority Scheduling Algorithm. Let's discuss the algorithms one by one first and then establish how Round Robin is a special kind of Preemptive Priority Scheduling Algorithm. Prerequisite - CPU Scheduling | Difference between Priority and Round Robin (RR) Schedu
2 min read
Priority to Round-robin scheduling with dynamic time quantum
Prerequisite - Program for Round Robin scheduling Processes are executed on basis of their priority in this scheduling algorithm. Processes have a specific priority associated with them on arrival. When a process arrives its priority is compared with other processes in the ready queue and if its priority is higher then it becomes running process. I
2 min read
Calculate server loads using Round Robin Scheduling
Given M servers that handle multiple requests having infinite computational capability and arrays arrivalTime[] and processTime[] of size N denoting the arrival time and load time of N requests in the following manner: Each server is numbered from 0 to (M - 1) and the requests are given in strictly increasing order of time.Each request i is assigne
14 min read
Find the order of execution of given N processes in Round Robin Scheduling
Given an array arr[] representing burst time of N processes scheduled using the Round Robin Algorithm with given quantum time Q. Assuming that all the process arrive at time t = 0, the task is to find the order in which the process execute. Examples: Input: arr[] = {3, 7, 4}, q = 3Output: 0 2 1Explanation:The order of execution is as follows P0, P1
12 min read
Program for Round Robin Scheduling for the same Arrival time
Round Robin is a CPU scheduling algorithm where each process is cyclically assigned a fixed time slot. It is the preemptive version of the First come First Serve CPU Scheduling algorithm.  Round Robin CPU Algorithm generally focuses on Time Sharing technique. The period of time for which a process or job is allowed to run in a pre-emptive method is
15+ min read
Difference between Priority scheduling and Shortest Job First (SJF) CPU scheduling
1. Priority Scheduling Algorithm : Priority scheduling algorithm executes the processes depending upon their priority. Each process is allocated a priority and the process with the highest priority is executed first. Priorities can be defined internally as well as externally. Internal priorities are decided by the system depending upon the number o
3 min read
Multilevel Feedback Queue Scheduling (MLFQ) CPU Scheduling
Multilevel Feedback Queue Scheduling (MLFQ) CPU Scheduling is like Multilevel Queue(MLQ) Scheduling but in this process can move between the queues. And thus, much more efficient than multilevel queue scheduling. Characteristics of Multilevel Feedback Queue Scheduling: In a multilevel queue-scheduling algorithm, processes are permanently assigned t
5 min read
Completion time of a given process in round robin
We are given n-processes with their completion times in form of an array. We need to find the time instant when a given process p ends if the scheduling process is round robin and time slice is 1-sec. note : Array index start with 0. Examples : Input : arr[] = {3, 2, 4, 2}, p = 1 Output : Completion time = 6 Explanation : Snap of process for every
8 min read
Difference Between User-CPU-Time and System-CPU-Time in UNIX
There are two kinds of CPU time in any UNIX system: User CPU Time and System CPU Time. These metrics help in understanding the way in which the overall execution time is spent by any process using CPU resources. User CPU time is the total amount of time that the CPU spends executing both user processes and those parts of programs that run on behalf
8 min read
Operating Systems | CPU Scheduling | Question 1
Consider three processes (process id 0, 1, 2 respectively) with compute time bursts 2, 4 and 8 time units. All processes arrive at time zero. Consider the longest remaining time first (LRTF) scheduling algorithm. In LRTF ties are broken by giving priority to the process with the lowest process id. The average turn around time is: (A) 13 units (B) 1
1 min read
Operating Systems | CPU Scheduling | Question 2
Consider three processes, all arriving at time zero, with total execution time of 10, 20 and 30 units, respectively. Each process spends the first 20% of execution time doing I/O, the next 70% of time doing computation, and the last 10% of time doing I/O again. The operating system uses a shortest remaining compute time first scheduling algorithm a
2 min read
Operating Systems | CPU Scheduling | Question 3
Consider three CPU-intensive processes, which require 10, 20 and 30 time units and arrive at times 0, 2 and 6, respectively. How many context switches are needed if the operating system implements a shortest remaining time first scheduling algorithm? Do not count the context switches at time zero and at the end. (A) 1 (B) 2 (C) 3 (D) 4 Answer: (B)
1 min read
Operating Systems | CPU Scheduling | Question 4
Which of the following process scheduling algorithm may lead to starvation (A) FIFO (B) Round Robin (C) Shortest Job Next (D) None of the above Answer: (C) Explanation: Shortest job next may lead to process starvation for processes which will require a long time to complete if short processes are continually added.Quiz of this Question
1 min read
Operating Systems | CPU Scheduling | Question 5
If the quantum time of round robin algorithm is very large, then it is equivalent to: (A) First in first out (B) Shortest Job Next (C) Lottery scheduling (D) None of the above Answer: (A) Explanation: If time quantum is very large, then scheduling happens according to FCFS.Quiz of this Question
1 min read
Operating Systems | CPU Scheduling | Question 6
Which of the following is FALSE about SJF (Shortest Job First Scheduling)? S1: It causes minimum average waiting time S2: It can cause starvation (A) Only S1 (B) Only S2 (C) Both S1 and S2 (D) Neither S1 nor S2 Answer: (D) Explanation: Both SJF and Shortest Remaining time first algorithms may cause starvation. Consider a situation when long process
1 min read
Difference between Preemptive Priority based and Non-preemptive Priority based CPU scheduling algorithms
Prerequisite - CPU Scheduling Priority Scheduling : In priority scheduling, each process has a priority which is an integer value assigned to it. The smallest integer is considered as the highest priority and the largest integer is considered as the lowest priority. The process with the highest priority gets the CPU first. In rare systems, the larg
4 min read
Longest Remaining Time First (LRTF) CPU Scheduling Program
We have given some processes with arrival time and Burst Time and we have to find the completion time (CT), Turn Around Time(TAT), Average Turn Around Time (Avg TAT), Waiting Time(WT), Average Waiting Time (AWT) for the given processes. Prerequisite: CPU Scheduling | Longest Remaining Time First (LRTF) algorithm LRTF is a preemptive scheduling algo
15+ min read
Advantages and Disadvantages of various CPU scheduling algorithms
CPU Scheduling involves many different scheduling algorithms which have their Advantages and Disadvantages. 1. First Come First Serve (FCFS): Advantages: It is simple and easy to understand.FCFS provides fairness by treating all processes equally and giving them an equal opportunity to run.FCFS guarantees that every process will eventually get a ch
3 min read
Difference between SJF and LJF CPU scheduling algorithms
Shortest Job First: The shortest job first (SJF) algorithm is a CPU scheduling algorithm designed to reorder the jobs so that the process having the smallest burst time is chosen for the next execution. It is used to reduce the average waiting time for other processes waiting for execution. This may be preemptive or non-preemptive. Its preemptive v
4 min read
Fair-share CPU scheduling
Fair-share scheduling is a scheduling algorithm that was first designed by Judy Kay and Piers Lauder at Sydney University in the 1980s. It is a scheduling algorithm for computer operating systems that dynamically distributes the time quanta "equally" to its users. Time quantum is the processor time allowed for a process to run. But in a round-robin
2 min read
Difference between SJF and SRJF CPU scheduling algorithms
1. Shortest Job First (SJF) : The Shortest Job First (SJF) is a scheduling policy that selects the waiting process with the smallest execution time to execute next. It is also known as Shortest Job Next (SJN) or Shortest Process Next (SPN). It is a non-preemptive scheduling algorithm. 2. Shortest Remaining Job First (SRTF) : The Shortest Remaining
2 min read
Difference between SRJF and LRJF CPU scheduling algorithms
1. Shortest remaining job first (SRJF) : Shortest remaining job first also called the shortest remaining time first is the preemptive version of the shortest job first scheduling algorithm. In the shortest remaining job first, the process with the smallest runtime to complete (i.e remaining time) is scheduled to run next, In SRJF, a running process
3 min read
Difference between First Come First Served (FCFS) and Longest Job First (LJF) CPU scheduling algorithms
1.First Come First Served (FCFS) : First Come First Served (FCFS) is the simplest type of algorithm. It is a non-preemptive algorithm i.e. the process cannot be interrupted once it starts executing. The FCFS is implemented with the help of a FIFO queue. The processes are put into the ready queue in the order of their arrival time. The process that
3 min read
Difference between FCFS and Priority CPU scheduling
1. First Come First Served (FCFS) : First Come First Served (FCFS) is the simplest type of algorithm. It is a non-preemptive algorithm i.e. the process cannot be interrupted once it starts executing. The FCFS is implemented with the help of a FIFO queue. The processes are put into the ready queue in the order of their arrival time. The process that
3 min read