Narasimha Reddy
Narasimha Reddy
OPERATING SYSTEMS
Submitted by:
Page | 1
The methodology adopted to solve the problem:
To implement a scheduling program with two levels, we will use a
combination of fixed priority preemptive scheduling and round-robin scheduling.
We will have two queues, Queue 1 and Queue 2, where Queue 1 will have higher
priority than Queue 2.
For Queue 1, we will use fixed priority preemptive scheduling, where the process
with the highest priority (priority 0) will be executed first. If two processes have
the same priority, we will use round-robin scheduling to allocate the CPU time.
Each process in Queue 1 will be allocated CPU time in multiples of 2.
For Queue 2, we will use round-robin scheduling, where each process will be
allocated CPU time for a fixed time slice. Once a process finishes its time slice, it
will be moved to the end of the queue, and the next process will be scheduled.
To solve this problem, we can create two queues. The first queue will be used for
fixed priority preemptive scheduling and the second queue will be used for round-
robin scheduling. We can use a priority queue to implement the first queue where
priority 0 is the highest priority. If a process P1 is running and another process P2
with higher priority comes, then P2 preempts P1 and P1 will go to the second level
queue. The time for which a process will strictly execute must be considered in
multiples of 2.
Once Queue 1 becomes empty, Queue 2 will be processed. The priority of Queue
2 has lower priority than in Queue 1.
Page | 2
Implementation of Program :
#include<iostream>
#include<queue>
#include<vector>
using namespace std;
struct Process {
int pid;
int arrivalTime;
int burstTime;
int priority;
int remainingTime;
int quantum;
};
int main() {
vector<Process> processes = {
{1, 0, 8, 1, 8},
{2, 1, 4, 2, 4},
{3, 2, 9, 3, 9},
{4, 3, 5, 4, 5},
{5, 4, 2, 5, 2},
Page | 4
};
int quantum1 = 2;
int quantum2 = 2;
schedule(processes, quantum1, quantum2);
return 0;
}
OUTPUT SNAPSHOT:
Page | 5
Page | 6
Page | 7