-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProcessTable.java
More file actions
111 lines (100 loc) · 3.61 KB
/
ProcessTable.java
File metadata and controls
111 lines (100 loc) · 3.61 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
/******************************************************************
* A process table data structure
* Keeps track of 10 processes currently running in the background.
* @author Gloire Rubambiza
* @since 11/12/2017
******************************************************************/
public class ProcessTable {
/** The array of PCBs in the ready and running states. */
private PCB [] pcbTable;
/** The max amount of PCBs to be created. */
private int max = 10;
/*************************************************
* Instantiates an array of 10 PCBs to start with.
* Initializes all the PCBs with null page tables
************************************************/
public ProcessTable () {
this.pcbTable = new PCB [max];
int i, j = 1;
// Creates each new PCB
for ( i = 0; i < max; i++ ) {
this.pcbTable[i] = new PCB (j);
j++;
}
}
/************************************************************
* Updates page table of the given process with new entries.
* @param inTable tells where the page is being added/replaced
* @param pid is the PID of the process.
* @param page is the page to be added/replaced in the table.
* @return true if the update was successful, false otherwise.
*************************************************************/
public void updatePCB(boolean inTable, int pid, int page, int frame) {
int i;
for ( i = 0; i < 10; i++ ) {
if ( this.pcbTable[i].getPID() == pid ) {
this.pcbTable[i].updateTable(inTable, page, frame);
}
}
}
/***********************************************
* Updates the references count for the process.
* @param pid is the PID of the process.
***********************************************/
public void updatePCBRefCount ( int pid ) {
int i;
for ( i = 0; i < max; i++ ) {
if ( this.pcbTable[i].getPID() == pid ) {
this.pcbTable[i].updateRefCount();
}
}
}
/***********************************************
* Updates the page fault count for the process.
* @param pid is the PID of the process.
***********************************************/
public void updatePCBFaultCount ( int pid ) {
int i;
for ( i = 0; i < max; i++ ) {
if ( this.pcbTable[i].getPID() == pid ) {
this.pcbTable[i].updateFaults();
}
}
}
/********************************************************
* Prints the current state of the PCB's page table.
* @param pid is the PID of the process.
*********************************************************/
public void printPageTable( int pid ) {
System.out.println("Page Table : Process " + pid);
int i;
for ( i = 0; i < max; i++ ) {
if ( this.pcbTable[i].getPID() == pid ) {
this.pcbTable[i].printTable();
}
}
System.out.println();
}
/******************************************
* Prints the final stats for each process.
*******************************************/
public void printStats () {
System.out.println("-------------------------------------------------");
System.out.println("Final Stats\n");
System.out.println("Proc Refs Faults");
int i = 0;
for (i = 0; i < max; i++) {
int pid = this.pcbTable[i].getPID();
int totalRefs = this.pcbTable[i].getTotalReferences();
int totalFaults = this.pcbTable[i].getTotalPageFaults();
System.out.println(pid + "\t" + totalRefs + "\t" + totalFaults);
}
}
/*******************************************
* Returns a reference to the array of PCBs.
* @return an array of PCBs.
********************************************/
public PCB [] getPCBArray () {
return this.pcbTable;
}
}