-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPaging
More file actions
154 lines (119 loc) · 2.84 KB
/
Paging
File metadata and controls
154 lines (119 loc) · 2.84 KB
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#include<stdio.h>
int ms,ps,nop,np,rempages,i,j,x,y,offset;
int s[10],fno[10][20];
int a=0;
int pgt[20];
void display()
{
printf("\nPage no\t:\tStatus\n");
for(i=0;i<nop;i++)
printf("\n%d \t:\t%d",i,pgt[i]);
}
void delete()
{
int n1;
printf("Enter the process number : ");
scanf("%d",&n1);
if(n1>=a)
{
printf("Process invalid");
return;
}
for(i=0;i<s[n1];i++)
{
pgt[fno[n1][i]]=0;
rempages++;
}
display();
}
void enter()
{
printf("\nEnter no. of pages required for process -> %d : ",a);
scanf("%d",&s[a]);
if(s[a] >rempages)
{
printf("\nMemory is Full");
display();
a++;
return;
}
rempages = rempages - s[a];
printf("\nEnter pagetable for process -> %d : ",a);
for(j=0;j<s[a];j++)
{
scanf("%d",&fno[a][j]);
pgt[fno[a][j]]=1;
}
a++;
}
void findadd()
{
int choice;
while(1)
{
printf("\nEnter process number, page number and offset : ");
scanf("%d %d %d",&i,&j,&offset);
if(x>np || y>=s[i] || offset>=ps)
printf("\n\nInvalid Entry \n");
else
printf("\n\nThe Physical Address is %d",fno[i][j-1]*ps+offset);
printf("\nDo you want to continue (1.Yes / 2.No /) : ");
scanf("%d",&choice);
if(choice!=1)
break;
}
}
void main()
{
for(i=0;i<20;i++)
{
pgt[i]=0;
}
printf("\nEnter the memory size : ");
scanf("%d",&ms);
printf("\nEnter the page size : ");
scanf("%d",&ps);
nop = ms/ps;
printf("\nThe no. of pages available in memory = %d ",nop);
printf("\nEnter number of processes : ");
scanf("%d",&np);
rempages = nop;
for(i=0;i<np;i++)
{
printf("\nEnter no. of pages required for process -> %d : ",i);
scanf("%d",&s[i]);
if(s[i] >rempages)
{
printf("\nMemory is Full");
display();
break;
}
a++;
rempages = rempages - s[i];
printf("\nEnter pagetable for process -> %d : ",i);
for(j=0;j<s[i];j++)
{
scanf("%d",&fno[i][j]);
pgt[fno[i][j]]=1;
}
}
while(1)
{
int y;
printf("\n1. Terminate process");
printf("\n2. Enter process");
printf("\n3. Display Page table");
printf("\n4. Find Address");
printf("\n5. Exit");
printf("\nEnter your choice : ");
scanf("%d",&y);
switch(y)
{
case 1: delete();break;
case 2: enter();break;
case 3: display();break;
case 4:findadd(); break;
case 5: return;
}
}
}