Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 93 additions & 6 deletions interrupts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,34 @@ std::tuple<std::string, std::string, int> simulate_trace(std::vector<std::string
current_time = time;

///////////////////////////////////////////////////////////////////////////////////////////
//Add your FORK output here
execution += std::to_string(current_time) + ", 1, switch to kernel mode //fork encountered, "
+ std::to_string(wait_queue.size() + 1) + " processes in PCB\n";
current_time += 1;

execution += std::to_string(current_time) + ", 10, context saved\n";
current_time += 10;

execution += std::to_string(current_time) + ", 1, find vector 2 in memory position 0x0004\n";
current_time += 1;

execution += std::to_string(current_time) + ", 1, load address 0X0695 into the PC\n";
current_time += 1;

execution += std::to_string(current_time) + ", 17, cloning the PCB\n";
current_time += 17;

execution += std::to_string(current_time) + ", 0, scheduler called\n";
execution += std::to_string(current_time) + ", 1, IRET\n";
current_time += 1;

// Create child PCB and put parent in wait queue
PCB child(current.PID + 1, current.PID, current.program_name, current.size, current.partition_number);
wait_queue.push_back(current); // parent goes to wait queue
current = child; // child runs immediately

// Snapshot system status
system_status += print_PCB(current, wait_queue);




Expand Down Expand Up @@ -90,7 +117,15 @@ std::tuple<std::string, std::string, int> simulate_trace(std::vector<std::string
i = parent_index;

///////////////////////////////////////////////////////////////////////////////////////////
//With the child's trace, run the child (HINT: think recursion)
auto [child_exec, child_status, child_time] = simulate_trace(child_trace, current_time, vectors, delays, external_files, current, wait_queue);
execution += child_exec;
system_status += child_status;
current_time = child_time;

// After child finishes, restore parent
current = wait_queue.back();
wait_queue.pop_back();




Expand All @@ -103,8 +138,43 @@ std::tuple<std::string, std::string, int> simulate_trace(std::vector<std::string
execution += intr;

///////////////////////////////////////////////////////////////////////////////////////////
//Add your EXEC output here

// EXEC ISR: load new program into memory and log
execution += std::to_string(current_time) + ", 1, switch to kernel mode //exec encountered\n";
current_time += 1;

execution += std::to_string(current_time) + ", 10, context saved\n";
current_time += 10;

execution += std::to_string(current_time) + ", 1, find vector 3 in memory position 0x0006\n";
current_time += 1;

execution += std::to_string(current_time) + ", 1, load address 0X042B into the PC\n";
current_time += 1;

unsigned int prog_size = get_size(program_name, external_files);
current.program_name = program_name;
current.size = prog_size;

execution += std::to_string(current_time) + ", " + std::to_string(duration_intr) + ", Program is " + std::to_string(prog_size) + " Mb large\n";
current_time += duration_intr;

execution += std::to_string(current_time) + ", " + std::to_string(prog_size * 15) + ", loading program into memory\n";
current_time += prog_size * 15;

execution += std::to_string(current_time) + ", 3, marking partition as occupied\n";
current_time += 3;

execution += std::to_string(current_time) + ", 6, updating PCB\n";
current_time += 6;

execution += std::to_string(current_time) + ", 0, scheduler called\n";
execution += std::to_string(current_time) + ", 1, IRET\n";
current_time += 1;

// Snapshot PCB
system_status += print_PCB(current, wait_queue);




///////////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -119,7 +189,24 @@ std::tuple<std::string, std::string, int> simulate_trace(std::vector<std::string
}

///////////////////////////////////////////////////////////////////////////////////////////
//With the exec's trace (i.e. trace of external program), run the exec (HINT: think recursion)
// Run child or external program recursively
std::ifstream prog_file(program_name + ".txt");
std::vector<std::string> prog_traces;
std::string line;
while (std::getline(prog_file, line)) prog_traces.push_back(line);

auto [prog_exec, prog_status, prog_time] = simulate_trace(prog_traces, current_time, vectors, delays, external_files, current, wait_queue);

execution += prog_exec;
system_status += prog_status;
current_time = prog_time;

// After child finishes, restore parent if needed
if (!wait_queue.empty()) {
current = wait_queue.back();
wait_queue.pop_back();
}




Expand Down Expand Up @@ -156,7 +243,7 @@ int main(int argc, char** argv) {
std::vector<PCB> wait_queue;

/******************ADD YOUR VARIABLES HERE*************************/

int child_counter = 0;

/******************************************************************/

Expand Down