Future Vision BIE Future Vision BIE


ONE STOP FOR ALL STUDY MATERIALS & LAB PROGRAMS


E MENU Whatsapp Share Join Telegram, to get Instant Updates
× NOTE! Click on MENU to Browse between Subjects...

Advertisement

SYSTEM SOFTWARE AND OPERATING SYSTEM LABORATORY

[As per Choice Based Credit System (CBCS) scheme]

(Effective from the academic year 2017 - 2018)

SEMESTER - VI

Subject Code 17CSL67

IA Marks 40

Number of Lecture Hours/Week 01I + 02P

Exam Marks 60



17CSL67 - SYSTEM SOFTWARE AND OPERATING SYSTEM LABORATORY

Program 9

Design, develop and implement a C/C++/Java program to implement page replacement algorithms LRU and FIFO. Assume suitable input required to demonstrate the results




Advertisement



Advertisement

 1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#include<stdio.h>
#include<stdlib.h>

void FIFO(char [ ],char [ ],int,int);
void lru(char [ ],char [ ],int,int);
void opt(char [ ],char [ ],int,int);

int main()
{
    int ch,YN=1,i,l,f;
    char F[10],s[25];
    printf("\nEnter the no of empty frames: ");
    scanf("%d",&f);
    printf("\nEnter the length of the string: ");
    scanf("%d",&l);
    printf("\nEnter the string: ");
    scanf("%s",s);
    for(i=0;i<f;i++)
        F[i]=-1;

    do
    {
        printf("\n*********** MENU ***********");
        printf("\n1:FIFO\n2:LRU \n3:EXIT");
        printf("\nEnter your choice: ");
        scanf("%d",&ch);

        switch(ch)
        {
            case 1: for(i=0;i<f;i++)
                        F[i]=-1;
                    FIFO(s,F,l,f);
                    break;

            case 2: for(i=0;i<f;i++)
                        F[i]=-1;
                    lru(s,F,l,f);
                    break;

            case 3: exit(0);
        }
        printf("\n\nDo u want to continue IF YES PRESS 1\nIF NO PRESS 0 : ");
        scanf("%d",&YN);
    } while(YN==1);
    return(0);
}

//FIFO
void FIFO(char s[],char F[],int l,int f)
{
    int i,j=0,k,flag=0,cnt=0;
    printf("\n\tPAGE\t	FRAMES\t\t\t FAULTS");
    for(i=0;i<l;i++)
    {
        for(k=0;k<f;k++)
        {
            if(F[k]==s[i])
                flag=1;
        }

        if(flag==0)
        {
            printf("\n\t%c\t",s[i]);
            F[j]=s[i];
            j++;
            for(k=0;k<f;k++)
                printf("	%c",F[k]);
            printf("\tPage-fault%d",cnt);
            cnt++;
        }

        else
        {
            flag=0;
            printf("\n\t%c\t",s[i]);
            for(k=0;k<f;k++)
                printf("	%c",F[k]);
            printf("\tNo page-fault");
        }
        if(j==f)
            j=0;
    }
}

//LRU
void lru(char s[],char F[],int l,int f)
{
    int i,j=0,k,m,flag=0,cnt=0,top=0;
    printf("\n\tPAGE\t	FRAMES\t\t\t FAULTS");
    for(i=0;i<l;i++)
    {
        for(k=0;k<f;k++)
        {
            if(F[k]==s[i])
            {
                flag=1;
                break;
            }
        }
        printf("\n\t%c\t",s[i]);
        if(j!=f && flag!=1)
        {
            F[top]=s[i];
            j++;
            if(j!=f)
                top++;
        }

        else
        {
            if(flag!=1)
            {
                for(k=0;k<top;k++)
                    F[k]=F[k+1];
                F[top]=s[i];
            }

            if(flag==1)
            {
                for(m=k;m<top;m++)
                    F[m]=F[m+1];
                F[top]=s[i];
            }
        }

        for(k=0;k<f;k++)
            printf("	%c",F[k]);

        if(flag==0)
        {
            printf("\tPage-fault%d",cnt);
            cnt++;
        }
        else
            printf("\tNo page fault");
        flag=0;
    }
}

Output


Program Output



× Note Page Number is specified to navigate between Pages...
SYS = Syllabus
P = Program


-ADMIN



× Note Do Share the website link with Your Friends and known Students...

-ADMIN

lIKE OUR CONTENT SUPPORT US BY FOLLOWING US ON INSTAGRAM : @futurevisionbie

Latest Updates are also posted in instagram as Stories...

For immediate Notification Join the Telegram Channel




Advertisement