sppo.cpp

 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
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <cstdlib>
#include <iostream>
#include <stdlib.h>
#include "process.h"
Dispatcher GOD;
int main()
{
while (1)
{
int q;
string tempStr;
int tempNumb;
Process mas[5];
int i = 0;
cin >> q;
if (q == 1)
{
cout << "Input name of process" << endl;
cin >> tempStr;
mas[i].SetName(tempStr);
cout << "Input memory" << endl;
cin >> tempNumb;
mas[i].SetMEMORY(tempNumb);
cout << "Input PID" << endl;
cin >> tempNumb;
mas[i].SetPID(tempNumb);
cout << "Input number of segments" << endl;
cin >> tempNumb;
mas[i].SetNSegments(tempNumb);
for (int j = 0 ; j < mas[i].GetNSegments(); j++)
{
cout << "Input memory of segment" << endl;
cin >> mas[i].segments[j].size;
}
GOD.proc.push_back(mas[i]);
/*
for (int j = 0; j < mas[i].GetNSegments(); j++)
{
for(int k = 0; k < mas[i].segments[j]; k++)
{
int *mas = new int[n];
realloc(mas, n * sizeof(int));
}
}
*/
for(int j = 0; j < 5; j++){
if(GOD.freeMem() >= GOD.proc[GOD.proc.size()-1].segments[j].size)
{
if(!GOD.proc[GOD.proc.size()-1].segments[j].status)
GOD.AntiSwap(GOD.proc[GOD.proc.size()-1].segments[j].size,
GOD.proc[GOD.proc.size()-1]);
}
else
if(GOD.proc.size() > 1)
for(int l = 0; l < 5; l++)
GOD.Swap(GOD.proc[GOD.proc.size()-1].segments[l].size, true,
mas[i - 1]);
else
for(int l = 0; l < 5; l++)
GOD.Swap(GOD.proc[GOD.proc.begin()+1].segments[l].size, true,
mas[1]);
}
}
}
return 0;
}