0% found this document useful (0 votes)
34 views3 pages

Osy Code

The document describes a methodology for multi-level feedback queue scheduling. It defines three queues Q1, Q2, and Q3 with different time quantums. Processes are prioritized by queue and processes in higher priority queues will preempt those in lower priority queues. Pseudocode is provided to implement this scheduling algorithm.

Uploaded by

Free fire Garena
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views3 pages

Osy Code

The document describes a methodology for multi-level feedback queue scheduling. It defines three queues Q1, Q2, and Q3 with different time quantums. Processes are prioritized by queue and processes in higher priority queues will preempt those in lower priority queues. Pseudocode is provided to implement this scheduling algorithm.

Uploaded by

Free fire Garena
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

3.

Methodology Followed
Let’s consider there are three queues Q1, Q2 and Q3.

• Q1 Time quantum 9 milliseconds


Q2 Time quantum 18 milliseconds
Q3 FCFS

• Criteria of Multilevel Feedback Queue –

▪ The scheduler first executes all processes in Q1.


▪ Only when Q1 is empty will it executes processes in Q2.
▪ Similarly, processes in Q3 will be executed only if Q1 and Q2 are empty.
▪ A process that arrives for Q2 will preempt a process in Q3.
▪ A process that arrives for Q3 will, in turn, preempt a process in Q3.

MultiLevel FeedBack Queue Scheduling Example

• Explanation
Any process entering the ready queue is put in Q1. Then, A process in Q1 is given a time quantum of 9
milliseconds. If it does not finish within time, it is moved to the tail of Q2.
If Q1 is empty, the process at the head of Q2 is given a quantum of 18 milliseconds. or, If it does not complete, it
is preempted and is put into Q3.
Processes in Q3 are run on an FCFS basis, only when Q1 and Q2 are empty.

Coding:

#include<stdio.h>

#define N 10

typedef struct
{
SANDIP POLYTECHNIC
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++)
{
SANDIP POLYTECHNIC
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;
}

SANDIP POLYTECHNIC

You might also like