0% found this document useful (0 votes)
11 views4 pages

RR Scheduling With Priority

The document outlines modifications to a Round Robin scheduling algorithm to incorporate a Priority Scheduling feature. It details the steps to implement a priority array, modify the scheduling algorithm to sort processes by priority, and update the output to display process priorities alongside other metrics. Sample input and output are provided to illustrate the expected results of the updated implementation.

Uploaded by

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

RR Scheduling With Priority

The document outlines modifications to a Round Robin scheduling algorithm to incorporate a Priority Scheduling feature. It details the steps to implement a priority array, modify the scheduling algorithm to sort processes by priority, and update the output to display process priorities alongside other metrics. Sample input and output are provided to illustrate the expected results of the updated implementation.

Uploaded by

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

Round Robin Scheduling with Priority Feature

Task Description:
Modify the given Round Robin scheduling implementation to include a Priority Scheduling
feature. The updated program should execute processes in a priority-based manner if two
or more processes have the same burst time. If priorities are equal, the Round Robin
approach should handle the time-sharing.
Steps to Implement the Task:
1. Add a Priority Array:
- Introduce a new integer array `priority[]` that holds the priority values of each process.
Higher priority is represented by a lower value (e.g., 1 is higher than 2).
2. Modify the RR Algorithm:
- Before starting the Round Robin scheduling, sort the processes based on their priority.
- If two or more processes have the same priority, process them in the order they appear
in the array (Round Robin logic applies).
3. Update the Output:
- Display the priority of each process in the final table, alongside the Process ID, Burst
Time, Waiting Time, and Turnaround Time.

Previous task code implementation is Given below use this code and convert it
into Priority Round Robin
implementation of RR scheduling
#include <iostream>
using namespace std;

// Function to find the waiting time for all


// processes
void findWaitingTime(int processes[], int n, int bt[], int wt[], int
quantum)
{
// Make a copy of burst times bt[] to store remaining
// burst times.
int rem_bt[n];
for (int i = 0; i < n; i++)
rem_bt[i] = bt[i];

int t = 0; // Current time

// Keep traversing processes in round robin manner


// until all of them are not done.
while (1)
{
bool done = true;

// Traverse all processes one by one repeatedly


for (int i = 0; i < n; i++)
{
// If burst time of a process is greater than 0
// then only need to process further
if (rem_bt[i] > 0)
{
done = false; // There is a pending process

if (rem_bt[i] > quantum)


{
// Increase the value of t i.e. shows
// how much time a process has been processed
t += quantum;

// Decrease the burst_time of current process


// by quantum
rem_bt[i] -= quantum;
}

// If burst time is smaller than or equal to


// quantum. Last cycle for this process
else
{
// Increase the value of t i.e. shows
// how much time a process has been processed
t = t + rem_bt[i];

// Waiting time is current time minus time


// used by this process
wt[i] = t - bt[i];

// As the process gets fully executed


// make its remaining burst time = 0
rem_bt[i] = 0;
}
}
}

// If all processes are done


if (done == true)
break;
}
}

// Function to calculate turn around time


void findTurnAroundTime(int processes[], int n, int bt[], int wt[], int
tat[])
{
// calculating turnaround time by adding
// bt[i] + wt[i]
for (int i = 0; i < n; i++)
tat[i] = bt[i] + wt[i];
}
// Function to calculate average time
void findavgTime(int processes[], int n, int bt[], int quantum)
{
int wt[n], tat[n], total_wt = 0, total_tat = 0;

// Function to find waiting time of all processes


findWaitingTime(processes, n, bt, wt, quantum);

// Function to find turn around time for all processes


findTurnAroundTime(processes, n, bt, wt, tat);

// Display processes along with all details


cout << "PN\t "
<< " \tBT "
<< " \tWT "
<< " \tTAT\n";

// Calculate total waiting time and total turn


// around time
for (int i = 0; i < n; i++)
{
total_wt = total_wt + wt[i];
total_tat = total_tat + tat[i];
cout << " " << i + 1 << "\t\t" << bt[i] << "\t " << wt[i] << "\
t\t " << tat[i] << endl;
}

cout << "Average waiting time = " << (float)total_wt / (float)n;


cout << "\nAverage turn around time = " << (float)total_tat /
(float)n;
}

// Driver code
int main()
{
// process id's
int processes[] = {1, 2, 3};
int n = sizeof processes / sizeof processes[0];

// Burst time of all processes


int burst_time[] = {10, 5, 8};

// Time quantum
int quantum = 2;
findavgTime(processes, n, burst_time, quantum);
return 0;
}

Sample Input and Output:


Input:
Processes: {1, 2, 3}
Burst Time: {10, 5, 8}
Priority: {2, 1, 3}
Time Quantum: 2

Output:
PN BT Priority WT TAT
1 10 2 8 18
2 5 1 0 5
3 8 3 14 22

Average waiting time = 7.33


Average turn around time = 15.00

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy