0% found this document useful (0 votes)
3 views1 page

Os Lab

The document contains C code for implementing First-Come, First-Served (FCFS) and Round Robin (RR) scheduling algorithms. It includes structures for processes, input for burst times, and calculations for waiting and turnaround times. The program outputs average waiting and turnaround times for the processes after execution.

Uploaded by

aghimire
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)
3 views1 page

Os Lab

The document contains C code for implementing First-Come, First-Served (FCFS) and Round Robin (RR) scheduling algorithms. It includes structures for processes, input for burst times, and calculations for waiting and turnaround times. The program outputs average waiting and turnaround times for the processes after execution.

Uploaded by

aghimire
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

FCFS: scanf("%d",&n);

#include<stdio.h> for(i=1;i<=n;i++){
#include<conio.h> x[i].pid=i;
struct process{ printf("\nEnter the Burst Time:\t");
int pid; int bt; int wt,tt; scanf("%d",&x[i].bt);
}p[10]; tot=tot+x[i].bt;
int main(){ }
int i,n,totwt,tottt,avg1,avg2; printf("\nTotal Burst Time:\t%d",tot);
printf("enter the no of process \n"); p[0].tt=0;
scanf("%d",&n); k=1;
for(i=1;i<=n;i++){ printf("\nEnter the Time Slice:\t");
p[i].pid=i; scanf("%d",&m);
printf("enter the burst time \n"); for(j=1;j<=tot;j++){
scanf("%d",&p[i].bt); for(i=1;i<=n;i++){
} if(x[i].bt!=0){
p[1].wt=0; p[k].pid=i;
p[1].tt=p[1].bt+p[1].wt; if(x[i].bt-m<0){
i=2; p[k].wt=p[k-1].tt;
while(i<=n){ p[k].bt=x[i].bt;
p[i].wt=p[i-1].bt+p[i-1].wt; p[k].tt=p[k].wt+x[i].bt;
p[i].tt=p[i].bt+p[i].wt; x[i].bt=0;
i++; k++;
} }
i=1; else{
totwt=tottt=0; p[k].wt=p[k-1].tt;
printf("\n processid \t bt\t wt\t tt\n"); p[k].tt=p[k].wt+m;
while(i<=n){ x[i].bt=x[i].bt-m;
printf("\n\t%d \t%d \t%d \t k++;
%d",p[i].pid,p[i].bt,p[i].wt,p[i].tt); }}}
totwt=p[i].wt+totwt; }
tottt=p[i].tt+tottt; printf("\nProcess id \twt \ttt");
i++; for(i=1;i<k;i++){
} printf("\n\t%d \t%d \t%d",p[i].pid,p[i].wt,p[i].tt);
avg1=totwt/n; avg2=tottt/n; wttime=wttime+p[i].wt;
printf("\navg1=%d \t avg2=%d \t",avg1,avg2); tottime=tottime+p[i].tt;
getch(); a1=wttime/n;
return 0; a2=tottime/n;
} }
printf("\n\nAverage Waiting Time:\t%f",a1);
RR Scheduling printf("\n\nAverage TurnAround Time:\t
#include<stdio.h> %f",a2);
#include<conio.h> getch();
struct process{ return 0;
int pid,bt,tt,wt; }
};
int main()
{
struct process x[10],p[30];
int i,j,k,tot=0,m,n;
float wttime=0.0,tottime=0.0,a1,a2;
printf("\nEnter the number of process:\t");

You might also like