Assignment4 OSL 222059
Assignment4 OSL 222059
•Aim:-
1)FCFS:-
• Theory:-
• Code FCFS:-
#include<stdio.h>
int main()
{
int n,bt[20],wt[20],tat[20],avwt=0,avtat=0,i,j;
printf("Enter total number of processes(maximum
20):");
scanf("%d",&n);
printf("\nProcess\t\tBurst Time\tWaiting
Time\tTurnaround Time");
//calculating turnaround time
for(i=0;i<n;i++)
{
tat[i]=bt[i]+wt[i];
avwt+=wt[i];
avtat+=tat[i];
printf("\nP[%d]\t\t%d\t\t%d\t\t%d",i+1,bt[i],wt[i],tat[i]);
}
avwt/=i;
avtat/=i;
printf("\n\nAverage Waiting Time:%d",avwt);
printf("\nAverage Turnaround Time:%d",avtat);
return 0;
}
• Output:-
2)SJF:-
• Theory:-
Here you will get C program for (SJF)
scheduling algorithm.
In shortest job first scheduling
algorithm, the processor selects the waiting process with
the smallest execution time to execute next.
• Code:-
#include<stdio.h>
void main()
{
int
bt[20],p[20],wt[20],tat[20],i,j,n,total=0,pos,temp;
float avg_wt,avg_tat;
printf("Enter number of process:");
scanf("%d",&n);
temp=bt[i];
bt[i]=bt[pos];
bt[pos]=temp;
temp=p[i];
p[i]=p[pos];
p[pos]=temp;
}
total+=wt[i];
}
avg_wt=(float)total/n; //average waiting
time
total=0;