Round Robin Algorithm With Examples
Round Robin Algorithm With Examples
operating system, which assigns time slices to each process in equal portions and in circular
order handling all processes without priority arguably, the major issue in RR is the time slice .
Round Robin scheduling is both simple and easy to implement, and starvation-free. Different
variants of Round Robin scheduling can be applied to other scheduling problems such as data
packet scheduling in computer networks . Effectiveness and efficiency of RR are arising from
its low scheduling overhead O(1) of which means scheduling the next task takes a constant
time...
Waiting time - amount of time a process has been waiting in the ready queue.
want to minimize time process is in the system but not running
less dependent on process length
Response time - amount of time it takes from when a request was submitted until the first
response is produced.
in a time-sharing environment, want to minimize interaction time for user
rule-of-thumb:
response time of 0.1 sec req'd to make interaction seem instantaneous
response time of 1.0 sec req'd for user's flow of thought to stay uninterrupted
response time of 10 sec req'd to keep user's attention focused
rt = t(first response) t(submission of request)
Context Switching:
Context switching is how the computer's operating system multitasks different
processes. It lets one process run for a while and then saves a copy of the process' run state
(such as register values) off to the side, restores the run state of the next process back into the
processor, and runs it for a while. Context switching is this process of swapping one program
out of the CPU and replacing it with another process.
Working:
If there are n processes in the ready queue and the time quantum is q, then each
process gets 1/n of the CPU time in chunks of at most q time units at once. No
process waits more than (n-1)q time units.
Performance of the round robin algorithm
I.
q large FCFS
II.
q small q must be greater than the context switch time; otherwise, the
overhead is too high
In order to schedule processes fairly, a round-robin scheduler generally employs timesharing, giving each job a time slot or quantum (its allowance of CPU time), and
interrupting the job if it is not completed by then. The job is resumed next time a time slot is
assigned to that process. In the absence of time-sharing, or if the quanta were large relative to
the sizes of the jobs, a process that produced large jobs would be favored over other
processes... In a computer for example, the user starts three applications, Email, a
web browser, and a word processor. These applications are loaded into system
memory as processes and each is allowed to run without the user considering
which applications are running in the background. Round-robin scheduling handles the
sharing of resources between the three application processes (and the countless others running
in the background completely invisible to the user). This scheduling works well because each
application gets a certain amount of time per processor cycle. A processor cycle is the amount
of time it takes the CPU to manage each process running, one time. With round robin
scheduling, interactive performance depends on the length of the quantum and the number of
processes in the run queue. A very long quantum makes the algorithm behave very much like
first come, first served scheduling since its very likely that a process with block or complete
before the time slice is up. A small quantum lets the system cycle through processes quickly.
This is wonderful for interactive processes. Unfortunately, there is an overhead to context
switching and having to do so frequently increases the percentage of system time that is used
on context switching rather than real work.
There is a Queue of processes that need to work on and each process has it's time
requirement to complete,
eg:
process processor time
A3
B8
C6
D4
if the processor give 1 processor time to each process , then A->B->C->D will run each taking
1 processor time and complete a cycle and each process that is not complete will add to the
end of the queue, if a process is completed it will remove from the queue(not enqueueing).
This process will continue until all the process are completed and the queue is empty.
Above que will work as follows.
A->B->C->D->A->B->C->D->A->B->C->D>B->C->D->B->C->B->C->B->B-> Que is
empty
in each highlighted position process that complete their process time remove from the queue
and therefore the rest are processing according to queue.
Advantages:
simple, low overhead, works for interactive systems
Disadvantages: if quantum is too small, too much time
wasted in context switching; if too large (i.e. longer than
mean CPU burst), approaches FCFS.
Working Diagram:-
Exapmle 1 :
Time Quantum = 4
Process
Burst Time
P1
24
P2
P3
P1
P2
P3
P1
10
P1
14
P1
18
P1
22
P1
26
30
Exapmle 2:
Time Quantum=3 units
Process=4
Process
Arrival Time
Execute Time
P0
P1
P2
P3
P0
P1
P2
P3
P0
P2
P3
P2
12
15
18
21
P0
(0-0) + (12-3) = 9
P1
(3-1) = 2
P2
6-2) + (15-9) = 10
24
P3
(9-3) + (18-12) = 12