In this lab, you will implement the priority scheduling algorithm based on the nice value for xv6.
1. Write a user level program nice.c that will accepts two arguments: pid and priority which will change the nice value of the process with process id pid to priority, i.e. nice pid priority.
#include<bits/stdc++.h>
using namespace std;
struct Process
{
int pid; // Process ID
int bt; // CPU Burst time required
int priority; // Priority of this process
};
// Function to sort the Process acc. to priority
bool comparison(Process a, Process b)
{
return (a.priority > b.priority);
}
// Function to find the waiting time for all
// processes
void findWaitingTime(Process proc[], int n,
int wt[])
{
// waiting time for first process is 0
wt[0] = 0;
// calculating waiting time
for (int i = 1; i < n ; i++ )
wt[i] = proc[i-1].bt + wt[i-1] ;
}
// Function to calculate turn around time
void findTurnAroundTime( Process proc[], int n,
int wt[], int tat[])
{
// calculating turnaround time by adding
// bt[i] + wt[i]
for (int i = 0; i < n ; i++)
tat[i] = proc[i].bt + wt[i];
}
Get Answers For Free
Most questions answered within 1 hours.