Question
#include #include struct task { int pid; int burst; struct task *next; }; typedef struct task node; int count=0; // to keep no of processes
#include
#include
struct task
{
int pid;
int burst;
struct task *next;
};
typedef struct task node;
int count=0; // to keep no of processes
node* head=NULL; //head node
node* last=NULL; //last node
//function to read each process busrt time and store it in linked list
void insert(int value)
{
node *temp_node;
temp_node = (node *) malloc(sizeof(node)); //allocate memory
temp_node->burst=value; //store valu
temp_node->pid=count;
temp_node->next=NULL;
//For the 1st element
if(head==NULL)
{
head=temp_node;
last=temp_node;
}
else
{
last->next=temp_node;
last=temp_node;
}
count++;
}
void FCFS()
{
int st[count];
st[0]=0;
int i=0;
int tat[count];
st[0] = 0;
int wt[count];
wt[0]=0;
int bt[count];
node *llist;
llist = head;
//printf(" FCFS ");
float sum =0.0, avgTat=0.0;
//read busrt time from list
while(llist!=NULL)
{
bt[i] = llist->burst;
i++;
llist = llist->next;
}
// calculating waiting time
for ( i = 1; i
// Add burst time of previous processes
st[i] = st[i-1] + bt[i-1];
wt[i] = st[i] - 0;
if (wt[i]
wt[i] = 0;
}
for ( i = 0; i
tat[i] = bt[i] + wt[i];
for(i =0 ;i { sum+=wt[i]; avgTat+=tat[i]; printf("P%d ", i); } printf(" Average Waiting Time = %f avg Turn around Time = %f ", sum/(count), avgTat/count); } void rr() { int k,i,j,n,time,remain,flag=0,quantum; int wait_time=0,turnaround_time=0,at[10],bt[10],rt[10]; node *llist; llist = head; n=count; remain=n; for(i=0;i { at[i]=0; } i=0; while(llist!=NULL) { bt[i]=rt[i] = llist->burst; i++; llist = llist->next; } quantum=10; for(time=0,i=0;remain!=0;) { if(rt[i]0) { printf("P%d ", i); time+=rt[i]; rt[i]=0; flag=1; } else if(rt[i]>0) { printf("P%d ", i); rt[i]-=quantum; time+=quantum; } if(rt[i]==0 && flag==1) { remain--; wait_time+=time-at[i]-bt[i]; turnaround_time+=time-at[i]; flag=0; } if(i==n-1) i=0; else if(at[i+1] i++; else i=0; } printf(" Average Waiting Time= %f ",wait_time*1.0); printf(" Avg Turnaround Time = %f ",turnaround_time*1.0); } int main(int argc, char *argv[]){ if(strcmp(argv[1],"0")==0) { FILE *input = fopen(argv[2], "r"); int burst_time; while(fscanf(input, "%d", &burst_time)!=EOF) { insert(burst_time); } FCFS(); } else if(strcmp(argv[1],"1")==0){ FILE *input = fopen(argv[2], "r"); int burst_time; while(fscanf(input, "%d", &burst_time)!=EOF){ insert(burst_time); } rr(); } else { printf(" available options 0: FCFS 1: Round Robin "); } return 0; } i have some error hor this code in putty programe
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started