Multilevel Queue (MLQ) CPU Scheduling

Last Updated : 05 May, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

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 a background (batch) process. These two classes have different scheduling needs. For this kind of situation, Multilevel Queue Scheduling is used. 

Now, let us see how it works. 

Features of Multilevel Queue (MLQ) CPU Scheduling:

  • Multiple queues: In MLQ scheduling, processes are divided into multiple queues based on their priority, with each queue having a different priority level. Higher-priority processes are placed in queues with higher priority levels, while lower-priority processes are placed in queues with lower priority levels.
  • Priorities assigned: Priorities are assigned to processes based on their type, characteristics, and importance. For example, interactive processes like user input/output may have a higher priority than batch processes like file backups.
  • Preemption: Preemption is allowed in MLQ scheduling, which means a higher priority process can preempt a lower priority process, and the CPU is allocated to the higher priority process. This helps ensure that high-priority processes are executed in a timely manner.
  • Scheduling algorithm: Different scheduling algorithms can be used for each queue, depending on the requirements of the processes in that queue. For example, Round Robin scheduling may be used for interactive processes, while First Come First Serve scheduling may be used for batch processes.
  • Feedback mechanism: A feedback mechanism can be implemented to adjust the priority of a process based on its behavior over time. For example, if an interactive process has been waiting in a lower-priority queue for a long time, its priority may be increased to ensure it is executed in a timely manner.
  • Efficient allocation of CPU time: MLQ scheduling ensures that processes with higher priority levels are executed in a timely manner, while still allowing lower priority processes to execute when the CPU is idle.
  • Fairness: MLQ scheduling provides a fair allocation of CPU time to different types of processes, based on their priority and requirements.
  • Customizable: MLQ scheduling can be customized to meet the specific requirements of different types of processes.

Advantages of Multilevel Queue CPU Scheduling:

  • Low scheduling overhead: Since processes are permanently assigned to their respective queues, the overhead of scheduling is low, as the scheduler only needs to select the appropriate queue for execution.
  • Efficient allocation of CPU time: The scheduling algorithm ensures that processes with higher priority levels are executed in a timely manner, while still allowing lower priority processes to execute when the CPU is idle. This ensures optimal utilization of CPU time.
  • Fairness: The scheduling algorithm provides a fair allocation of CPU time to different types of processes, based on their priority and requirements.
  • Customizable: The scheduling algorithm can be customized to meet the specific requirements of different types of processes. Different scheduling algorithms can be used for each queue, depending on the requirements of the processes in that queue.
  • Prioritization: Priorities are assigned to processes based on their type, characteristics, and importance, which ensures that important processes are executed in a timely manner.
  • Preemption: Preemption is allowed in Multilevel Queue Scheduling, which means that higher-priority processes can preempt lower-priority processes, and the CPU is allocated to the higher-priority process. This helps ensure that high-priority processes are executed in a timely manner.

Disadvantages of Multilevel Queue CPU Scheduling:

  • Some processes may starve for CPU if some higher priority queues are never becoming empty.
  • It is inflexible in nature.
  • There may be added complexity in implementing and maintaining multiple queues and scheduling algorithms.

Ready Queue is divided into separate queues for each class of processes. For example, let us take three different types of processes System processes, Interactive processes, and Batch Processes. All three processes have their own queue. Now, look at the below figure. 

The Description of the processes in the above diagram is as follows:

  • System Processes: The CPU itself has its own process to run which is generally termed a System Process.
  • Interactive Processes: An Interactive Process is a type of process in which there should be the same type of interaction.
  • Batch Processes: Batch processing is generally a technique in the Operating system that collects the programs and data together in the form of a batch before the processing starts.

All three different type of processes have their own queue. Each queue has its own Scheduling algorithm. For example, queue 1 and queue 2 use Round Robin while queue 3 can use FCFS to schedule their 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 the lower priority queue. Let us consider the following priority order queue 1 > queue 2 > queue 3. According to this algorithm, no process in the batch queue(queue 3) can run unless queues 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 a 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 the below table of four processes under Multilevel queue scheduling. Queue number denotes the queue of the process. 

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: 

 

Working:

  • 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 seconds and 
  • After its completion P3 takes the CPU and completes its execution. 

 



Similar Reads

Difference between Multilevel Queue (MLQ) and Multi Level Feedback Queue (MLFQ) CPU scheduling algorithms
In multi programming environment, it often happens that more than one processes compete for CPU resources at the same time. If only one CPU is available choice has to be made between processes to run next. Part of the Operating System responsible for making choice of process is called Scheduler and the algorithm it used is called Scheduling Algorit
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
Difference between Multi Level Queue Scheduling (MLQ) and Priority Scheduling
1. Multi Level Queue Scheduling (MLQ) : It is quite difficult to have just one queue and schedule all processes. This is where multi-level queue scheduling is used. In this, processes are divided into various classes depending upon property of processes such as system process, I/O process, etc. Thus we get 'n' number of queues for n classes of proc
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
Difference between Multi Level Queue Scheduling (MLQ) and First Come First Served (FCFS)
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 c
3 min read
Difference between Multi Level Queue Scheduling (MLQ) and Shortest Job First
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 c
3 min read
Difference between Multi Level Queue Scheduling (MLQ) and Longest Job First (LJF)
1. Multi Level Queue Scheduling (MLQ) : It is quite difficult to have just one queue and schedule all processes. This is where multi-level queue scheduling is used. In this, processes are divided into various classes depending upon property of processes such as system process, I/O process, etc. Thus we get 'n' number of queues for n classes of proc
3 min read
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 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
Difference Between User-CPU-Time and System-CPU-Time in UNIX
Unix systems have a time utility that allows a user to see where their application took significant time to process. The syntax of this utility is as follows: time <command-to-be-timed>Its result generally has three categories as follows: real <time> user <time> sys <time>User CPU time and system CPU time are both measures o
3 min read
Article Tags :
Practice Tags :