0% found this document useful (0 votes)
53 views4 pages

Lab Assignment 1 Scheduling

This document provides code to simulate the first come first served (FCFS) CPU scheduling algorithm. The code takes in the arrival times and burst times of processes as input. It then calculates the waiting times and turnaround times of each process using FCFS. It outputs the average waiting time and average turnaround time. The code contains functions for FCFS scheduling and for taking input from the user.

Uploaded by

payal lolaoa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views4 pages

Lab Assignment 1 Scheduling

This document provides code to simulate the first come first served (FCFS) CPU scheduling algorithm. The code takes in the arrival times and burst times of processes as input. It then calculates the waiting times and turnaround times of each process using FCFS. It outputs the average waiting time and average turnaround time. The code contains functions for FCFS scheduling and for taking input from the user.

Uploaded by

payal lolaoa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Lab Assignment 1

Scheduling

Q1 ]Write a program to simulate the following non-preemptive CPU


scheduling algorithms to find turnaround time and waiting time.
a) FCFS
#include<stdio.h>

void fcfs(int at[],int bt[], int size)


{
int i,sum=0;
int Wt[size],Tat[size],s[size];
float avg_wt=0.0,avg_tat=0.0;
Wt[0]=0; //Zero for the 1st
process
s[0]=0;
for(i=1;i<size;i++) //Calculating the
waiting time
{
s[i]=s[i-1]+bt[i-1];
Wt[i]=s[i]-at[i];
if(Wt[i]<0)
{
Wt[i]=0;
}
sum=sum+Wt[i];
}
for(i=0;i<size;i++) //Calculating the
turn around time
{
Tat[i]=bt[i]+Wt[i];
avg_tat=avg_tat+Tat[i];
}
avg_wt=(float)sum/(float)size;
avg_tat=avg_tat/size;
printf("THE AVERAGE WT FOR FCFS IS: %f\n",avg_wt);
printf("THE AVERAGE TAT FOR FCFS IS:
%f\n\n",avg_tat);

int main()
{
int n,i;
printf(" ENTER THE NO OF
PROCESSES \n ");
scanf("%d",&n);
int Id[n],At[n],Bt[n],pri[n];
for(i=0;i<n;i++)
{
printf("\nENTER THE ID OF PROCESS\n");
scanf("%d",&Id[i]);
}
for(i=0;i<n;i++)
{
printf("\nENTER THE ARRIVAL TIME OF
PROCESS\n");
scanf("%d",&At[i]);
}
for(i=0;i<n;i++)
{
printf("\nENTER THE BURST TIME OF
PROCESS\n");
scanf("%d",&Bt[i]);
}
for(i=0;i<n;i++)
{
printf("\nENTER THE ID OF PROCESS\n");
scanf("%d",&pri[i]);
}
fcfs(At,Bt,n);
return(0);
}

You might also like