Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#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

image text in transcribed

S gcc -Wall -o scheduler scheduler.c cheduler.c: In function 'rr' cheduler.c:78:9: warning: unused variable 'j'-Wunused-variable] int k,i,,n,time, remain, flag-0, quantum cheduler.c:78:5: warning: unused variable 'k' -Wunused-variable] int k,i,jn,time, remain, flag-0,quantum; cheduler.c: I n function main': cheduler.c:130:2: warning: implicit declaration of function 'strcmp' -Wimplici -function-declaration] if (strcmp (argv [1],"0") 0)<>

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning Databases With PostgreSQL From Novice To Professional

Authors: Richard Stones, Neil Matthew

2nd Edition

1590594789, 978-1590594780

More Books

Students also viewed these Databases questions

Question

What are negative messages? (Objective 1)

Answered: 1 week ago