Priority MLQ RR Fairshare Cpu Scheduling
Priority MLQ RR Fairshare Cpu Scheduling
Priority MLQ RR Fairshare Cpu Scheduling
1. Priority Scheduling
In Priority scheduling, there is a priority number assigned to each process. In some systems, the lower the
number, the higher the priority. While, in the others, the higher the number, the higher will be the priority.
The Process with the higher priority among the available processes is given the CPU. There are two types of
priority scheduling algorithm exists. One is Preemptive priority scheduling while the other is Non
Preemptive Priority scheduling.
The priority number assigned to each of the process may or may not vary. If the priority number doesn't
change itself throughout the process, it is called static priority, while if it keeps changing itself at the
regular intervals, it is called dynamic priority.
Example
In the Example, there are 7 processes P1, P2, P3, P4, P5, P6 and P7. Their priorities, Arrival Time and burst
time are given in the table.
Process ID Priority Arrival Time Burst Time
1 2 0 3
2 6 2 5
3 3 1 4
4 5 4 2
5 7 6 9
6 4 5 4
7 10 7 10
We can prepare the Gantt chart according to the Non Preemptive priority scheduling.
The Process P1 arrives at time 0 with the burst time of 3 units and the priority number 2. Since No other
process has arrived till now hence the OS will schedule it immediately.
Meanwhile the execution of P1, two more Processes P2 and P3 are arrived. Since the priority of P3 is 3
hence the CPU will execute P3 over P2.
Meanwhile the execution of P3, All the processes get available in the ready queue. The Process with the
lowest priority number will be given the priority. Since P6 has priority number assigned as 4 hence it will be
executed just after P3.
After P6, P4 has the least priority number among the available processes; it will get executed for the whole
burst time.
Since all the jobs are available in the ready queue hence All the Jobs will get executed according to their
priorities. If two jobs have similar priority number assigned to them, the one with the least arrival time will
be executed.
From the GANTT Chart prepared, we can determine the completion time of every process. The turnaround
time, waiting time and response time will be determined.
1. Turn Around Time = Completion Time - Arrival Time
2. Waiting Time = Turn Around Time - Burst Time
The difference between preemptive priority scheduling and non preemptive priority scheduling is that, in the
preemptive priority scheduling, the job which is being executed can be stopped at the arrival of a higher
priority job.
Once all the jobs get available in the ready queue, the algorithm will behave as non-preemptive priority
scheduling, which means the job scheduled will run till the completion and no preemption will be done.
Example
There are 7 processes P1, P2, P3, P4, P5, P6 and P7 given. Their respective priorities, Arrival Times and
Burst times are given in the table below.
Process Arrival
Priority Burst Time
Id Time
1 2(H) 0 1
2 6 1 7
3 3 2 3
4 5 3 6
5 4 4 5
6 10(L) 5 15
7 9 6 8
GANTT chart Preparation
At time 0, P1 arrives with the burst time of 1 units and priority 2. Since no other process is available hence
this will be scheduled till next job arrives or its completion (whichever is lesser).
At time 1, P2 arrives. P1 has completed its execution and no other process is available at this time hence the
Operating system has to schedule it regardless of the priority assigned to it.
The Next process P3 arrives at time unit 2, the priority of P3 is higher to P2. Hence the execution of P2 will
be stopped and P3 will be scheduled on the CPU.
During the execution of P3, three more processes P4, P5 and P6 becomes available. Since, all these three
have the priority lower to the process in execution so PS can't preempt the process. P3 will complete its
execution and then P5 will be scheduled with the priority highest among the available processes.
Meanwhile the execution of P5, all the processes got available in the ready queue. At this point, the
algorithm will start behaving as Non Preemptive Priority Scheduling. Hence now, once all the processes get
available in the ready queue, the OS just took the process with the highest priority and execute that process
till completion. In this case, P4 will be scheduled and will be executed till the completion.
Since P4 is completed, the other process with the highest priority available in the ready queue is P2. Hence
P2 will be scheduled next.
P2 is given the CPU till the completion. Since its remaining burst time is 6 units hence P7 will be scheduled
after this.
The only remaining process is P6 with the least priority, the Operating System has no choice unless of
executing it. This will be executed at the last.
The Completion Time of each process is determined with the help of GANTT chart. The turnaround time
and the waiting time can be calculated by the following formula.
1. Turnaround Time = Completion Time - Arrival Time
2. Waiting Time = Turn Around Time - Burst Time
Turn
Arrival Burst Completion Waiting
Process Id Priority around
Time Time Time Time
Time
1 2 0 1 1 1 0
2 6 1 7 22 21 14
3 3 2 3 5 3 0
4 5 3 6 16 13 7
5 4 4 5 10 6 1
6 10 5 15 45 40 25
7 9 6 8 30 24 16
Avg Waiting Time = (0+14+0+7+1+25+16)/7 = 63/7 = 9 units
A common division is made between foreground(or interactive) processes and background (or batch)
processes. These two types of processes have different response-time requirements, and so might have
different scheduling needs. In addition, foreground processes may have priority over background processes.
A multi-level queue scheduling algorithm partitions the ready queue into several separate queues. The
processes are permanently assigned to one queue, generally based on some property of the process, such as
memory size, process priority, or process type. Each queue has its own scheduling algorithm.
For example: separate queues might be used for foreground and background processes. The foreground
queue might be scheduled by Round Robin algorithm, while the background queue is scheduled by an FCFS
algorithm.
In addition, there must be scheduling among the queues, which is commonly implemented as fixed-priority
preemptive scheduling. For example: The foreground queue may have absolute priority over the
background queue.
1. System Processes
2. Interactive Processes
3. Interactive Editing Processes
4. Batch Processes
5. Student Processes
Each queue has absolute priority over lower-priority queues. No process in the batch queue, for example,
could run unless the queues for system processes, interactive processes, and interactive editing processes
were all empty. If an interactive editing process entered the ready queue while a batch process was running,
the batch process will be preempted.
3. Multilevel Feedback Queue Scheduling
In a multilevel queue-scheduling algorithm, processes are permanently assigned to a queue on entry to the
system. Processes do not move between queues. This setup has the advantage of low scheduling overhead,
but the disadvantage of being inflexible.
Multilevel feedback queue scheduling, however, allows a process to move between queues. The idea is to
separate processes with different CPU-burst characteristics. If a process uses too much CPU time, it will be
moved to a lower-priority queue. Similarly, a process that waits too long in a lower-priority queue may be
moved to a higher-priority queue. This form of aging prevents starvation.
The definition of a multilevel feedback queue scheduler makes it the most general CPU-scheduling
algorithm. It can be configured to match a specific system under design. Unfortunately, it also requires some
means of selecting values for all the parameters to define the best scheduler. Although a multilevel feedback
queue is the most general scheme, it is also the most complex.
Once a process is executed for a given time period, it is preempted and other process executes for a
given time period.
Time quantam is the processor time allowed for a process to run. But in a round-robin scheduling where the
time slices or time quanta are allocated equally in a circular order, due to the distribution of time slices in a
circular manner, any equal amount of time quanta will produce a similar output, therefore, an arbitrary
distribution is required in this scenario.
Specificity of Fair-share scheduling :
This algorithm equally distributes the processor time to its users, for instance, there are 5 users (A, B, C, D,
E)each of them are simultaneously executing a process, the scheduler divides the CPU periods such that all
the users get the same share of the CPU cycles (100%/5) that is 20%. Even though, a user moves onto the
second while the other at the first, the algorithm is so specific that it ensures that this user is attributed with
only 10% for the second process making it a total of 20%.
The scheduler logically divides an equal amount even though, another layer of partition is added, for
example, if there were 3 groups present with different number of people in each group, the algorithm would
still divide the same time for those groups, 100%/3= 33.33%, this 33.33% would be shared equally in the
respective group depending on the number of users present in the group.
To sum up, fair-share scheduling is an efficient strategy that creates a consistent user experience.