A system that can run multiple concurrent jobs on a single cpu have a process of choosing which taskhast to run when, and how to break them up, called "scheduling". the round-robin policy forscheduling runs each job for a fixed amount of time before switching to the next job. the waiting timefora job is the total time that it spends waiting to be run. each job arrives at particular time forscheduling and certain time to run, when a new job arrives, it is scheduled after existing jobs alreadywaiting for cpu timegiven list of job submission, calculate the average waiting time for all jobs using round-robin policy.the input to the function waitingtimerobin consist of two integer arrays containing job arrival and runtimes, an integer n representing number of jobs and am integer q representing the fixed amount oftime used by round-robin policy. the list of job arrival time and run time sorted in ascending order byarrival time. for jobs arriving at same time, process them in the order they are found in the arrival array.you can assume that jobs arrive in such a way that cpu is never idle.the function should return floating point value for the average waiting time which is calculated usinground robin policy.assume 0<=jobs arrival time < 100 and 0
Answers
"The average waiting time for all the jobs usingthe round-robin policy is as follows.The input to the function #include<stdio.h>
int waitingtimerobin(int *job,int *run,int n,int tq)
{
int j,count,time,remain,flag=0;
int wait_time=0,turnaround_time=0,rt[10];
remain=n;
for(count=0;count<n;c++)
{
rt[count]=run[count];
}
for(time=0,count=0;remain!=0;)
{
if(rt[count]<=tq && rt[count]>0)
{
time += rt[count];
rt[count]=0;
flag=1;
}
else if(rt[count]>0)
{
rt[count] -= time_quantum;
time += time_quantum;
}
if(rt[count]==0 && flag==1)
{
remain--;
wait_time += time-job[count]-run[count];
flag=0;
}
if(count==n-1)
count=0;
else if(job[count+1]<=time)
count++;
else
count=0;
}
printf(""waiting time %f"",wait_time*1.0/n);
return 0;
}
int main()
{
int ja[],at[];
int n,tq;
scanf(""%d"",&n);
for(i=0;i<n;i++)
{
scanf(""%d%d"", &ja[i],&at[i]);
}
scanf(""%d"",&tq);
int *cellsptr=ja;
int *cellsptr1=at;
waitingtimerobin(cellsptr,cellsptr1,n,tq);
return 0;
}"
showing error in the program