-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomputer.cpp
77 lines (61 loc) · 1.91 KB
/
computer.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
//
// Author: Osayamen Aimuyo
// Created: 1/29/2023.
//
#include <string>
#include <iostream>
#include <thread>
#include "computer/computer.h"
#include "computer/print.h"
#include "memory/memory.h"
#include "scheduler/scheduler.h"
#include "shell/shell.h"
#include "utility/utility.h"
int memorySize;
int TQ;
int mem_delay;
bool terminateFlag;
std::string ip_addr;
int port;
int CID;
int WS;
void read_system_parameters(){
char fname[20] = "config.txt";
FILE *config_file = fopen(fname, "r");
if (config_file == nullptr || feof(config_file)) {
perror("Invalid Configuration file");
}
else{
std::string line;
std::tie(std::ignore, line) = get_line(config_file);
ip_addr = line; // obtains printer's IP Address from config.sys file.
std::tie(std::ignore, line) = get_line(config_file);
port = std::stoi(line); // obtains printer's port from config.sys file.
std::tie(std::ignore, line) = get_line(config_file);
memorySize = std::stoi(line); // obtains M from config.sys file.
std::tie(std::ignore, line) = get_line(config_file);
TQ = std::stoi(line); // obtains time quantum from config.sys file.
mem_delay = TQ; // simulated memory delay for MLFQ scheduling
std::tie(std::ignore, line) = get_line(config_file);
WS = std::stoi(line); // obtains working set size from config.sys file.
}
}
void boot_system(char* arg){
terminateFlag = false;
CID = int(strtol(arg, nullptr, 10));
read_system_parameters();
}
int main(int argc, char* argv[]) {
std::thread::id main_id = std::this_thread::get_id();
boot_system(argv[1]);
load_init();
mem_init(memorySize);
process_scheduler_init();
print_init();
shell_init();
// needed to ensure orderly exit of destroyed, detached shell thread.
if(std::this_thread::get_id() == main_id) {
process_execute();
}
return 0;
}