Process scheduling algorithms You are about to write a program that performs run
ID: 3838591 • Letter: P
Question
Process scheduling algorithms You are about to write a program that performs runs of the following process scheduling algorithms using Cor Java programming Language: First-come first-served (FCFS) Shortest job first (SJF) Run each algorithm for 100 time slices, labeled 0 through 99. Before each run, generate a set of simulated processes. Each simulated process is simply a small data structure that stores information about the process that it represents For each process, randomly generate: An arrival time An burst time Assume only one CPU and one ready queue. Sort the simulated processes so that they enter the queue in arrival time order. For this assignment, only consider CPU time for each process (no LO wait times). Each simulation run should last until the completion of the last process, even if it goes beyond 100 quanta. Run each algorithm 5 times to get averages for the statistics below. Before each run, clear the process queue and create a new set of simulated processesExplanation / Answer
first_come.cpp
----------------------
#include<stdio.h>
int main()
{
int n,a[10],b[10],t[10],w[10],g[10],i,m;
float att=0,awt=0;
for(i=0;i<10;i++)
{
a[i]=0; b[i]=0; w[i]=0; g[i]=0;
}
printf("enter the number of process");
scanf("%d",&n);
printf("enter the burst times");
for(i=0;i<n;i++){
scanf("%d",&b[i]);
}
printf(" enter the arrival times");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
g[0]=0;
for(i=0;i<10;i++)
g[i+1]=g[i]+b[i];
for(i=0;i<n;i++)
{
w[i]=g[i]-a[i];
t[i]=g[i+1]-a[i];
awt=awt+w[i];
att=att+t[i];
}
awt =awt/n;
att=att/n;
printf(" process waiting time turn arround time ");
for(i=0;i<n;i++)
{
printf(" p%d %d %d ",i,w[i],t[i]);
}
printf("the average waiting time is %f ",awt);
printf("the average turn around time is %f ",att);
return 0;
}
sjf.cpp
----------
#include<stdio.h>
int main()
{
int bt[20],pre[20],wt[20],tat[20],i,j,n,total=0,pos,temp;
float avg_wt,avg_turn;
printf("Enter number of process: ");
scanf("%d",&n);
printf(" Enter Burst Time: ");
for(i=0;i<n;i++)
{
printf("p%d:",i+1);
scanf("%d",&bt[i]);
pre[i]=i+1;
}
for(i=0;i<n;i++)
{
pos=i;
for(j=i+1;j<n;j++)
{
if(bt[j]<bt[pos])
pos=j;
}
temp=bt[i];
bt[i]=bt[pos];
bt[pos]=temp;
temp=pre[i];
pre[i]=pre[pos];
pre[pos]=temp;
}
wt[0]=0;
for(i=1;i<n;i++)
{
wt[i]=0;
for(j=0;j<i;j++)
{
wt[i]+=bt[j];
}
total+=wt[i];
}
avg_wt=(float)total/n;
total=0;
printf(" Process Burst Time Waiting Time Turnaround Time");
for(i=0;i<n;i++)
{
tat[i]=bt[i]+wt[i];
total+=tat[i];
printf(" p%d %d %d %d",pre[i],bt[i],wt[i],tat[i]);
}
avg_turn=(float)total/n;
printf(" Average Waiting Time=%f",avg_wt);
printf(" Average Turnaround Time=%f ",avg_turn);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.