-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpcb.c
More file actions
57 lines (42 loc) · 1.19 KB
/
pcb.c
File metadata and controls
57 lines (42 loc) · 1.19 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
#include <stdio.h>
#include <stdlib.h>
#include "ram.h"
#include "pcb.h"
#include "kernel.h"
// "instanciate" PCB
struct PCB *makePCB(int start, int end, int pages_max){
struct PCB *nPCB = malloc (sizeof (struct PCB));
if (nPCB == NULL){
printf("Error : memory allocation for new PCB could not happen");
}
//nPCB-> start = start;
//nPCB->end = end;
nPCB->pages_max = pages_max;
nPCB->PC_offset = 0;
nPCB->PC_page=0;
// initialize page table when creating pcb when cell is -2 then the page has no frame associated
for (int i = 0; i < 10; i++){
nPCB->pageTable[i]=-2;
}
return nPCB;
}
// free the memory and clear the appropriate memory cells in ram
void clearPCB( struct PCB *nPCB){
for(int i=0;i<10;i++){
if(nPCB->pageTable[i]!=-2){
for(int j=nPCB->pageTable[i]*4;j<(nPCB->pageTable[i]*4)+4;j++){
//printf("clearing ram[%d]\n",j);
ram[j]=NULL;
}
pcbArray[nPCB->pageTable[i]]=NULL;
}
free(nPCB);
// update le pcbarrray
}
}
void clearFrame(struct PCB *thisPCB,int pageNumber){
for(int j=thisPCB->pageTable[pageNumber]*4;j<(thisPCB->pageTable[pageNumber]*4)+4;j++){
ram[j]=NULL;
}
thisPCB->pageTable[pageNumber]=-1;
}