The following processes are being scheduled using a preemptive, round-robin sche
ID: 3529646 • Letter: T
Question
The following processes are being scheduled using a preemptive, round-robin scheduling algorithm. Each process is assigned a numerical priority, with a higher number indicating a higher relative priority. In addition to the processes listed below, the system also has an idle task (which consumes no CPU resources and is identified as Pidle). This task has priority 0 and is scheduled whenever the system has no other available processes to run. The length of a time quantum is 10 units. If a process is placed at the end of the queue. a) Show the scheduling order of the processes using a Gantt chart. b) What is the turnaround time for each process? c) What is the waiting time for each process? d) What is the CPU utilization rate?
Explanation / Answer
#include<stdio.h>
#define true 1
#define false 0
int n,tq,totwt=0,tottrnd=0;
struct pr
{
int srvst,wt;
// int wt;
int trndt;
int flag;
int temp;
}prc[10];
void printpr()
{
printf(" Process_id Servicetime Waitingtime Turnarndtime ");int i;
for(i=0;i<n;i++)
{
printf(" %d %d %d %d ",i,prc[i].srvst,prc[i].wt,prc[i].trndt);
}
printf("Average waiting time=%f Average turnaroundtime=%f ",(float)totwt/n,(float)tottrnd/n);
}
void rschedule()
{
int trnd=0,i=0,t1;
while(completed()==false)
{
if(prc[i].flag==false)
{
if(prc[i].temp==0||prc[i].temp<=tq)
{
prc[i].flag=true;
trnd+=prc[i].temp;
tottrnd+=prc[i].trndt=trnd;
prc[i].temp=0;
}
else
{
trnd+=tq;
prc[i].temp-=tq;
}
}
i=(i+1)%n;
}
}
int completed()
{
int sum=0,i;
for(i=0;i<n;i++)
{
if(prc[i].flag==true)
sum++;
}
if(sum==n)
return true;
return false;
}
main()
{
int i;
printf(" <<<ROUND ROBIN SCHEDULING>>> Enter the timequantum: ");
scanf("%d",&tq);
printf("Enter the number of processes:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
//printf(" Enter the details for process %d: Service time:",i);
printf(" Enter process %d Service time:",i);
scanf("%d",&prc[i].srvst);
prc[i].flag=false;
prc[i].temp=prc[i].srvst;
}
prc[0].wt=0;int wtprmtr=0;
for(i=0;i<n-1;i++)
{
if(prc[i].srvst<tq)
wtprmtr+=prc[i].srvst;
else
wtprmtr+=tq;
prc[i+1].wt=wtprmtr;
totwt+=prc[i+1].wt;
}
rschedule();
printpr();
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.