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

Fifo Program

The document contains multiple C programs for different scheduling algorithms, including FIFO page replacement, Shortest Job First (SJF) with and without arrival times. Each program prompts the user for input, processes the data, and outputs relevant metrics such as page faults, waiting time, and turnaround time. The programs demonstrate basic concepts in operating systems related to process scheduling and memory management.

Uploaded by

Prajwal Auti
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)
4 views4 pages

Fifo Program

The document contains multiple C programs for different scheduling algorithms, including FIFO page replacement, Shortest Job First (SJF) with and without arrival times. Each program prompts the user for input, processes the data, and outputs relevant metrics such as page faults, waiting time, and turnaround time. The programs demonstrate basic concepts in operating systems related to process scheduling and memory management.

Uploaded by

Prajwal Auti
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

FIFO PROGRAM

#include<stdio.h>
#include<stdlib.h>
struct fnode
{
int pno;
}frames[5];

int ref_str[]={3,4,5,6,3,4,7,3,4,5,6,7,2,4,6};
int pfct=0,i,n,pno,p,flag=0;
int len=15;
int page_found(int pno)
{
for(i=0;i<n;i++)
if(frames[i].pno==pno)
return i;
return 0;
}
main()
{
printf("\nEnter no. of frames: ");
scanf("%d",&n);
printf("len:%d",len);
for(i=0;i<n;i++)
frames[i].pno=-1;
printf("\npage no page frames page_fault pfct");
printf("\n----------------------------------------------\n");
for(p=0;p<len;p++)
{
pno=ref_str[p];
flag=0;
if(page_found(pno)==0)
{
frames[pfct%n].pno=pno;
pfct++;
flag=1;
}
printf("\n%5d\t\t",pno);
for(i=0;i<n;i++)
printf("%d ",frames[i]);
if(flag==1)
printf("\tYES");
else
printf("\tNO");
printf("\t%d",pfct);

}
printf("\n----------------------------------------------\n");
printf("\nTotal no. of page fault : %d",pfct);
}

SJF PROGRAM

#include<stdio.h>
#include<conio.h>
#define max 30
void main()
{
int i,j,n,t,p[max],bt[max],wt[max],tat[max];
float awt=0,atat=0;
printf("Enter the number of process: ");
scanf("%d",&n);
printf("Enter the process number: ");
for(i=0;i<n;i++)
{
scanf("%d",&p[i]);
}
printf("Enter the Burst-time of the process: ");
for(i=0;i<n;i++)
{
scanf("%d",&bt[i]);
}
for(i=0;i<n;i++)
{
for(j=0;j<n-i-1;j++)
{
if(bt[j]>bt[j+1])
{
t=bt[j];
bt[j]=bt[j+1];
bt[j+1]=t;

t=p[j];
p[j]=p[j+1];
p[j+1]=t;
}
}
}
printf("process \t burst time \t waiting time \t turn around time\
n");
for(i=0;i<n;i++)
{
wt[i]=0;
tat[i]=0;
for(j=0;j<i;j++)
{
wt[i]=wt[i]+bt[i];
}
tat[i]=wt[i]+bt[i];
awt=awt=wt[i];
atat=atat+tat[i];
printf("%d\t\t %d\t\t %d\t\t %d\n",p[i],bt[i],wt[i],tat[i]);
}
awt=awt/n;
atat=atat/n;
printf("Average Waiting time: %f\n",awt);
printf("Average Turn around time: %f",atat);
getch();
}

With arrival time program

#include<stdio.h>
#include<conio.h>
#define max 30
void main()
{
int i,j,n,bt[max],at[max],wt[max],tat[max],temp[max];
float awt=0,atat=0;
printf("Enter the Number of process: ");
scanf("%d",&n);
printf("Enter the Burst Time of the Process:");
for(i=0;i<n;i++)
{
scanf("%d",&bt[i]);
}
printf("Enter the Arrival-Time of Process: ");
for ( i =0; i < n; i++)
{
scanf("%d",&at[i]);
}
temp[0]=0;
printf("process\t brust-time\t arrival-time\t waiting-time\t turn-
around time\n");
for(i=0;i<n;i++)
{
wt[i]=0;
tat[i]=0;
temp[i+1]=temp[i]+bt[i];
wt[i]=temp[i]-at[i];
tat[i]=wt[i]+bt[i];
awt=awt+wt[i];
atat=atat+tat[i];
printf("%d\t%d\t\t%d\t\t%d\t\t%d\
n",i+1,bt[i],at[i],wt[i],tat[i]);
}
awt=awt/n;
atat=atat/n;
printf("Average Waiting Time= %f\n",awt);
printf("Average Turn-around Time Time= %f",atat);
getch();
}

Without arrival time

#include<stdio.h>
#include<conio.h>
#define max 30
void main()
{
int i,j,n,bt[max],wt[max],tat[max];
float awt=0,atat=0;
printf("Enter the number of process:");
scanf("%d",&n);
printf("Enter the burst time of the process:");
for(i=0;i<n;i++)
{
scanf("%d",&bt[i]);
}
printf("process\t burst time\t waiting time \t turn around time\
n");
for(i=0;i<n;i++)
{
wt[i]=0;
tat[i]=0;
for(j=0;j<i;j++)
{
wt[i]=wt[i]+bt[j];
}
tat[i]=wt[i]+bt[i];
awt=awt+wt[i];
atat=atat+tat[i];
printf("%d\t\t%d\t\t%d\t\t%d\n",i+1,bt[i],wt[i],tat[i]);
}
awt=awt/n;
atat=atat/n;
printf("Average Waiting Time= %f\n",awt);
printf("Average Turn-around Time Time= %f",atat);
getch();
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy