C program to implement FIFO page replacement algorithm


http://1.bp.blogspot.com/-xvuJtp03d1w/TZshOxkcN3I/AAAAAAAAAQg/audiAJWiImg/s1600/c%2Band%2Bc%252B%252B%2Bmeansofmine.jpg
IMPLEMENTATION OF FIFO PAGE REPLACEMENT ALGORITHM

AIM

To write a c program to implement FIFO page replacement algorithm

ALGORITHM


1. Start the process

2. Declare the size with respect to page length

3. Check the need of replacement from the page to memory

4. Check the need of replacement from old page to new page in memory

5. Forma queue to hold all pages

6. Insert the page require memory into the queue

7. Check for bad replacement and page fault

8. Get the number of processes to be inserted

9. Display the values

10. Stop the process


PROGRAM:

#include<stdio.h>
int main()
{
int i,j,n,a[50],frame[10],no,k,avail,count=0;
            printf("\n ENTER THE NUMBER OF PAGES:\n");
scanf("%d",&n);
            printf("\n ENTER THE PAGE NUMBER :\n");
            for(i=1;i<=n;i++)
            scanf("%d",&a[i]);
            printf("\n ENTER THE NUMBER OF FRAMES :");
            scanf("%d",&no);
for(i=0;i<no;i++)
            frame[i]= -1;
                        j=0;
                        printf("\tref string\t page frames\n");
for(i=1;i<=n;i++)
                        {
                                    printf("%d\t\t",a[i]);
                                    avail=0;
                                    for(k=0;k<no;k++)
if(frame[k]==a[i])
                                                avail=1;
                                    if (avail==0)
                                    {
                                                frame[j]=a[i];
                                                j=(j+1)%no;
                                                count++;
                                                for(k=0;k<no;k++)
                                                printf("%d\t",frame[k]);
}
                                    printf("\n");
}
                        printf("Page Fault Is %d",count);
                        return 0;
}


OUTPUT:

ENTER THE NUMBER OF PAGES:  20
ENTER THE PAGE NUMBER :       7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 1
ENTER THE NUMBER OF FRAMES :3
      ref string       page frames
7               7       -1      -1
0               7       0       -1
1               7       0       1
2               2       0       1
0
3               2       3       1
0               2       3       0
4               4       3       0
2               4       2       0
3               4       2       3
0               0       2       3
3
2
1               0       1       3
2               0       1       2
0
1
7               7       1       2
0               7       0       2
1               7       0       1
Page Fault Is 15

26 comments:

John Spurgeon said...

how this will be executed

Anonymous said...

excellent and easy code
it has solved my confusion

Anonymous said...

too good

Anonymous said...

i really agree with you it has solved my confusion

Anonymous said...

thanks alot

Anonymous said...

wow...
good and easy logic implementation

thanq...

R.Ali said...

Great yOooooo!!!

R.Ali said...

Thanks yOooooo!!

Anonymous said...

thanks a lot, you made this program so easy....

Anonymous said...

bahi es ko explain bhi kar de to achha rahega

Anonymous said...

bahi es ko explain bhi kar de to achha rahega

Anonymous said...

thank you

Anonymous said...

Thanks.. it helps a lot.......

vamshi said...

very easy to understand.............

Anonymous said...

awesum(y)

Anonymous said...

my loops are not terminating

Gayatri said...

Gud logic

deebi abi said...

awesome...

deebi abi said...

very clear.

satish kolla said...

easy code

Anonymous said...

which program you used?

Anonymous said...

my faculty taught a vry hard code of this,,bt ds code seems t b vry easy den dat f my faculty...tnxx...

sanyog said...

why we need frames..as am beginner in this concept.. i dont kno..so plz tell me how it gets executed

Karthik KS said...

Nice logic

Karthik KS said...

Nice logic (yoooooo)

Anonymous said...

nice

Post a Comment