Let us learn how to implement multi level feedback queue scheduling algorithm in C programming with its explanation, output, advantages, disadvantages and much more.
What is Multi-Level Feedback Queue Scheduling Algorithm?
The multi-level feedback queue job scheduling algorithm primarily includes multiple job queues in the system. It scans the job queue and separates the jobs into different categories based on their need for the processor.
The algorithm allocates the jobs or processes to different queues based on their CPU execution time. If a process has a large burst-time, then it is automatically moved to a lower-priority queue. This technique helps to prevent starvation of lower priority processes too.
The algorithm prefers shorter jobs with low burst times and it prefers input/output bound processes. A process known as aging promotes lower priority jobs to a higher priority queue at regular intervals of time.
An important thing to note is that there is a difference between multi-level feedback queue scheduling algorithm and multi-level queue scheduling algorithm.
In the multi level feedback queue scheduling algorithm, the processes are permanently assigned to a queue whereas, in a multilevel feedback scheduling algorithm, the processes can move between multiple queues according to their requirements.
The multilevel feedback queue scheduling algorithm makes use of both first come first serve algorithm and shortest job first algorithm.

Advantages
- A high CPU time job that waits for too long in a lower priority queue can be moved to a higher priority queue at regular intervals of time.
Disadvantage
- Moving the processes from one queue to another increases the CPU overhead.
Note: This multilevel feedback queue scheduling algorithm in C programming is compiled with GNU GCC compiler using Linux terminal on Linux Ubuntu operating system.
C Program For Multilevel Feedback Queue Scheduling Algorithm
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | #include<stdio.h> #define N 10 typedef struct { int process_id, arrival_time, burst_time, priority; int q, ready; }process_structure; int Queue(int t1) { if(t1 == 0 || t1 == 1 || t1 == 2 || t1 == 3) { return 1; } else { return 2; } } int main() { int limit, count, temp_process, time, j, y; process_structure temp; printf("Enter Total Number of Processes:\t"); scanf("%d", &limit); process_structure process[limit]; for(count = 0; count < limit; count++) { printf("\nProcess ID:\t"); scanf("%d", &process[count].process_id); printf("Arrival Time:\t"); scanf("%d", &process[count].arrival_time); printf("Burst Time:\t"); scanf("%d", &process[count].burst_time); printf("Process Priority:\t"); scanf("%d", &process[count].priority); temp_process = process[count].priority; process[count].q = Queue(temp_process); process[count].ready = 0; } time = process[0].burst_time; for(y = 0; y < limit; y++) { for(count = y; count < limit; count++) { if(process[count].arrival_time < time) { process[count].ready = 1; } } for(count = y; count < limit - 1; count++) { for(j = count + 1; j < limit; j++) { if(process[count].ready == 1 && process[j].ready == 1) { if(process[count].q == 2 && process[j].q == 1) { temp = process[count]; process[count] = process[j]; process[j] = temp; } } } } for(count = y; count < limit - 1; count++) { for(j = count + 1; j < limit; j++) { if(process[count].ready == 1 && process[j].ready == 1) { if(process[count].q == 1 && process[j].q == 1) { if(process[count].burst_time > process[j].burst_time) { temp = process[count]; process[count] = process[j]; process[j] = temp; } else { break; } } } } } printf("\nProcess[%d]:\tTime:\t%d To %d\n", process[y].process_id, time, time + process[y].burst_time); time = time + process[y].burst_time; for(count = y; count < limit; count++) { if(process[count].ready == 1) { process[count].ready = 0; } } } return 0; } |
Output

If you have any doubts about the implementation of multi level feedback queue scheduling C program, let us know about it in the comment section. For more details, check Wikipedia.
Are Multilevel feedback queue and multilevel queue one and the same?
Hello, could you please tell me where you use the time quantum for each level?
Anyone can explain about queue function…?
In your code you have to be calculated time,what time is this complition time or turnaround time?
can you tell me how to make the same code using fcfs and round robin
and time quantum =8 and time quantum 16