Computer Science Engineering (CSE) Exam  >  Computer Science Engineering (CSE) Notes  >  Operating System  >  Multilevel Queue (MLQ) CPU Scheduling

Multilevel Queue (MLQ) CPU Scheduling | Operating System - Computer Science Engineering (CSE) PDF Download

It may happen that processes in the ready queue can be divided into different classes where each class has its own scheduling needs. For example, a common division is a foreground (interactive) process and background (batch) processes. These two classes have different scheduling needs. For this kind of situation Multilevel Queue Scheduling is used. Now, let us see how it works.
Ready Queue is divided into separate queues for each class of processes. For example, let us take three different types of process System processes, Interactive processes and Batch Processes. All three process have there own queue. Now, look at the below figure. 

Multilevel Queue (MLQ) CPU Scheduling | Operating System - Computer Science Engineering (CSE)

All three different type of processes have there own queue. Each queue have its own Scheduling algorithm. For example, queue 1 and queue 2 uses Round Robin while queue 3 can use FCFS to schedule there processes. 

Scheduling among the queues: What will happen if all the queues have some processes? Which process should get the cpu? To determine this Scheduling among the queues is necessary.
There are two ways to do so:

  1. Fixed priority preemptive scheduling method: Each queue has absolute priority over lower priority queue. Let us consider following priority order queue 1 > queue 2 > queue 3. According to this algorithm no process in the batch queue(queue 3) can run unless queue 1 and 2 are empty. If any batch process (queue 3) is running and any system (queue 1) or Interactive process(queue 2) entered the ready queue the batch process is preempted.
  2. Time slicing: In this method each queue gets certain portion of CPU time and can use it to schedule its own processes. For instance, queue 1 takes 50 percent of CPU time queue 2 takes 30 percent and queue 3 gets 20 percent of CPU time.

Example Problem: Consider below table of four processes under Multilevel queue scheduling. Queue number denotes the queue of the process.

Multilevel Queue (MLQ) CPU Scheduling | Operating System - Computer Science Engineering (CSE)

Priority of queue 1 is greater than queue 2. queue 1 uses Round Robin (Time Quantum = 2) and queue 2 uses FCFS.
Below is the gantt chart of the problem: 

Multilevel Queue (MLQ) CPU Scheduling | Operating System - Computer Science Engineering (CSE)

At starting both queues have process so process in queue 1 (P1, P2) runs first (because of higher priority) in the round robin fashion and completes after 7 units then process in queue 2 (P3) starts running (as there is no process in queue 1) but while it is running P4 comes in queue 1 and interrupts P3 and start running for 5 second and after its completion P3 takes the CPU and completes its execution. 

Advantages:

  • The processes are permanently assigned to the queue, so it has advantage of low scheduling overhead.

Disadvantages:

  • Some processes may starve for CPU if some higher priority queues are never becoming empty.
  • It is inflexible in nature.

Multilevel Feedback Queue Scheduling (MLFQ) CPU Scheduling

This Scheduling is like Multilevel Queue(MLQ) Scheduling but in this process can move between the queues. Multilevel Feedback Queue Scheduling (MLFQ) keep analyzing the behavior (time of execution) of processes and according to which it changes its priority. Now, look at the diagram and explanation below to understand it properly.

Multilevel Queue (MLQ) CPU Scheduling | Operating System - Computer Science Engineering (CSE)

Now let us suppose that queue 1 and 2 follow round robin with time quantum 4 and 8 respectively and queue 3 follow FCFS. One implementation of MFQS is given below:

  1. When a process starts executing then it first enters queue 1.
  2. In queue 1 process executes for 4 unit and if it completes in this 4 unit or it gives CPU for I/O operation in this 4 unit than the priority of this process does not change and if it again comes in the ready queue than it again starts its execution in Queue 1.
  3. If a process in queue 1 does not complete in 4 unit then its priority gets reduced and it shifted to queue 2.
  4. Above points 2 and 3 are also true for queue 2 processes but the time quantum is 8 unit. In a general case if a process does not complete in a time quantum than it is shifted to the lower priority queue.
  5. In the last queue, processes are scheduled in FCFS manner.
  6. A process in lower priority queue can only execute only when higher priority queues are empty.
  7. A process running in the lower priority queue is interrupted by a process arriving in the higher priority queue.

Well, above implementation may differ for example the last queue can also follow Round-robin Scheduling. 

Problems in the above implementation: A process in the lower priority queue can suffer from starvation due to some short processes taking all the CPU time.
Solution: A simple solution can be to boost the priority of all the process after regular intervals and place them all in the highest priority queue. 

What is the need of such complex Scheduling? 

  1. Firstly, it is more flexible than the multilevel queue scheduling.
  2. To optimize turnaround time algorithms like SJF is needed which require the running time of processes to schedule them. But the running time of the process is not known in advance. MFQS runs a process for a time quantum and then it can change its priority(if it is a long process). Thus it learns from past behavior of the process and then predicts its future behavior. This way it tries to run shorter process first thus optimizing turnaround time.
  3. MFQS also reduces the response time.

Example: Consider a system which has a CPU bound process, which requires the burst time of 40 seconds. The multilevel Feed Back Queue scheduling algorithm is used and the queue time quantum ‘2’ seconds and in each level it is incremented by ‘5’ seconds.Then how many times the process will be interrupted and on which queue the process will terminate the execution? 
Solution:

  • Process P needs 40 Seconds for total execution. 
  • At Queue 1 it is executed for 2 seconds and then interrupted and shifted to queue 2. 
  • At Queue 2 it is executed for 7 seconds and then interrupted and shifted to queue 3. 
  • At Queue 3 it is executed for 12 seconds and then interrupted and shifted to queue 4. 
  • At Queue 4 it is executed for 17 seconds and then interrupted and shifted to queue 5. 
  • At Queue 5 it executes for 2 seconds and then it completes. 
  • Hence the process is interrupted 4 times and completes on queue 5. 

Advantages:

  1. It is more flexible.
  2. It allows different processes to move between different queues.
  3. It prevents starvation by moving a process that waits too long for lower priority queue to the higher priority queue.

Disadvantages:

  1. For the selection of the best scheduler, it require some other means to select the values.
  2. It produces more CPU overheads.
  3. It is most complex algorithm.
The document Multilevel Queue (MLQ) CPU Scheduling | Operating System - Computer Science Engineering (CSE) is a part of the Computer Science Engineering (CSE) Course Operating System.
All you need of Computer Science Engineering (CSE) at this link: Computer Science Engineering (CSE)
10 videos|99 docs|33 tests

Top Courses for Computer Science Engineering (CSE)

FAQs on Multilevel Queue (MLQ) CPU Scheduling - Operating System - Computer Science Engineering (CSE)

1. What is multilevel queue CPU scheduling?
Ans. Multilevel queue CPU scheduling is a scheduling algorithm where processes are divided into multiple queues based on their priority or characteristics. Each queue has its own scheduling algorithm and priority level, allowing processes with higher priority to be executed first.
2. How does multilevel queue CPU scheduling work?
Ans. In multilevel queue CPU scheduling, processes are assigned to different queues based on their priority. Each queue has its own scheduling algorithm, such as round-robin or first-come-first-serve. The scheduler selects a process from the highest priority queue and executes it until it completes or a higher priority process arrives. This allows for efficient execution of processes based on their importance or characteristics.
3. What are the advantages of multilevel queue CPU scheduling?
Ans. Multilevel queue CPU scheduling offers several advantages: - Allows for proper prioritization of processes based on their importance or characteristics. - Provides fairness by ensuring that processes with lower priority are not starved. - Enables efficient utilization of CPU resources by executing high-priority processes first. - Supports multiple scheduling algorithms, allowing for customization based on the nature of processes in each queue.
4. What are the challenges of implementing multilevel queue CPU scheduling?
Ans. Implementing multilevel queue CPU scheduling can pose some challenges: - Determining the appropriate number of queues and their priority levels can be complex. - Balancing the allocation of CPU time between queues can be challenging to ensure fairness and optimal resource utilization. - Handling process movements between queues based on changing priorities or characteristics can add complexity to the scheduling algorithm. - Designing efficient mechanisms for inter-queue communication and synchronization can be difficult.
5. Can multilevel queue CPU scheduling be combined with other scheduling algorithms?
Ans. Yes, multilevel queue CPU scheduling can be combined with other scheduling algorithms to enhance its effectiveness. For example, a multilevel feedback queue scheduling algorithm combines the benefits of multilevel queue scheduling with feedback mechanisms. This allows processes to move between queues based on their behavior and performance, providing more flexibility in handling different types of processes.
10 videos|99 docs|33 tests
Download as PDF
Explore Courses for Computer Science Engineering (CSE) exam

Top Courses for Computer Science Engineering (CSE)

Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev
Related Searches

Objective type Questions

,

pdf

,

mock tests for examination

,

Free

,

practice quizzes

,

Extra Questions

,

MCQs

,

shortcuts and tricks

,

video lectures

,

study material

,

Multilevel Queue (MLQ) CPU Scheduling | Operating System - Computer Science Engineering (CSE)

,

Semester Notes

,

Viva Questions

,

Multilevel Queue (MLQ) CPU Scheduling | Operating System - Computer Science Engineering (CSE)

,

Summary

,

ppt

,

Important questions

,

Previous Year Questions with Solutions

,

past year papers

,

Exam

,

Sample Paper

,

Multilevel Queue (MLQ) CPU Scheduling | Operating System - Computer Science Engineering (CSE)

;