-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpaging.c
More file actions
55 lines (51 loc) · 1.22 KB
/
paging.c
File metadata and controls
55 lines (51 loc) · 1.22 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
#include<stdio.h>
#include<math.h>
void main(){
int memory_size,page_size;
printf("Enter Memory Size:");
scanf("%d",&memory_size);
printf("Enter Page Size:");
scanf("%d",&page_size);
int n=memory_size/page_size;
printf("No.of Pages available=%d\n",n);
int m[n],i,j;
for(i=0;i<n;i++){
m[i]=0;
}
int p;
printf("\nEnter No.of Processes:");
scanf("%d",&p);
int rem_pages=n;
int req_pages,process_size;
for(i=0;i<p;i++){
printf("Enter Process %d size:",i+1);
scanf("%d",&process_size);
req_pages=(process_size/page_size);
if(process_size%page_size!=0) req_pages++;
if(req_pages>rem_pages){
printf("Memory is lower than asked");
continue;
}
int temp[req_pages];
printf("Enter %d page numbers that are to be assigned to process %d:",req_pages,i+1);
for(j=0;j<req_pages;j++){
scanf("%d",&temp[j]);
}
for(j=0;j<req_pages;j++){
if(m[temp[j]]!=0){
printf("Page %d is already allocated",temp[j]);
break;
}
m[temp[j]]=i+1;
rem_pages--;
}
}
printf("Main Memory:\n");
printf("------------\n");
for(i=0;i<n;i++){
if(m[i]==0)
printf("\tframe %d -- EMPTY\n",i);
else
printf("\tframe %d -- process %d\n",i,m[i]);
}
}