diff --git a/bin/interrupts_EP.dSYM/Contents/Info.plist b/bin/interrupts_EP.dSYM/Contents/Info.plist
new file mode 100644
index 0000000..a81ef5f
--- /dev/null
+++ b/bin/interrupts_EP.dSYM/Contents/Info.plist
@@ -0,0 +1,20 @@
+
+
+
+
+ CFBundleDevelopmentRegion
+ English
+ CFBundleIdentifier
+ com.apple.xcode.dsym.interrupts_EP
+ CFBundleInfoDictionaryVersion
+ 6.0
+ CFBundlePackageType
+ dSYM
+ CFBundleSignature
+ ????
+ CFBundleShortVersionString
+ 1.0
+ CFBundleVersion
+ 1
+
+
diff --git a/bin/interrupts_EP.dSYM/Contents/Resources/DWARF/interrupts_EP b/bin/interrupts_EP.dSYM/Contents/Resources/DWARF/interrupts_EP
new file mode 100644
index 0000000..11f39c6
Binary files /dev/null and b/bin/interrupts_EP.dSYM/Contents/Resources/DWARF/interrupts_EP differ
diff --git a/bin/interrupts_EP.dSYM/Contents/Resources/Relocations/x86_64/interrupts_EP.yml b/bin/interrupts_EP.dSYM/Contents/Resources/Relocations/x86_64/interrupts_EP.yml
new file mode 100644
index 0000000..10609d3
--- /dev/null
+++ b/bin/interrupts_EP.dSYM/Contents/Resources/Relocations/x86_64/interrupts_EP.yml
@@ -0,0 +1,5 @@
+---
+triple: 'x86_64-apple-darwin'
+binary-path: 'bin/interrupts_EP'
+relocations: []
+...
diff --git a/bin/interrupts_EP_RR b/bin/interrupts_EP_RR
new file mode 100755
index 0000000..dab6b99
Binary files /dev/null and b/bin/interrupts_EP_RR differ
diff --git a/bin/interrupts_EP_RR.dSYM/Contents/Info.plist b/bin/interrupts_EP_RR.dSYM/Contents/Info.plist
new file mode 100644
index 0000000..f9da0ec
--- /dev/null
+++ b/bin/interrupts_EP_RR.dSYM/Contents/Info.plist
@@ -0,0 +1,20 @@
+
+
+
+
+ CFBundleDevelopmentRegion
+ English
+ CFBundleIdentifier
+ com.apple.xcode.dsym.interrupts_EP_RR
+ CFBundleInfoDictionaryVersion
+ 6.0
+ CFBundlePackageType
+ dSYM
+ CFBundleSignature
+ ????
+ CFBundleShortVersionString
+ 1.0
+ CFBundleVersion
+ 1
+
+
diff --git a/bin/interrupts_EP_RR.dSYM/Contents/Resources/DWARF/interrupts_EP_RR b/bin/interrupts_EP_RR.dSYM/Contents/Resources/DWARF/interrupts_EP_RR
new file mode 100644
index 0000000..f20b302
Binary files /dev/null and b/bin/interrupts_EP_RR.dSYM/Contents/Resources/DWARF/interrupts_EP_RR differ
diff --git a/bin/interrupts_EP_RR.dSYM/Contents/Resources/Relocations/x86_64/interrupts_EP_RR.yml b/bin/interrupts_EP_RR.dSYM/Contents/Resources/Relocations/x86_64/interrupts_EP_RR.yml
new file mode 100644
index 0000000..c8d9f5a
--- /dev/null
+++ b/bin/interrupts_EP_RR.dSYM/Contents/Resources/Relocations/x86_64/interrupts_EP_RR.yml
@@ -0,0 +1,5 @@
+---
+triple: 'x86_64-apple-darwin'
+binary-path: 'bin/interrupts_EP_RR'
+relocations: []
+...
diff --git a/bin/interrupts_RR.dSYM/Contents/Info.plist b/bin/interrupts_RR.dSYM/Contents/Info.plist
new file mode 100644
index 0000000..0046418
--- /dev/null
+++ b/bin/interrupts_RR.dSYM/Contents/Info.plist
@@ -0,0 +1,20 @@
+
+
+
+
+ CFBundleDevelopmentRegion
+ English
+ CFBundleIdentifier
+ com.apple.xcode.dsym.interrupts_RR
+ CFBundleInfoDictionaryVersion
+ 6.0
+ CFBundlePackageType
+ dSYM
+ CFBundleSignature
+ ????
+ CFBundleShortVersionString
+ 1.0
+ CFBundleVersion
+ 1
+
+
diff --git a/bin/interrupts_RR.dSYM/Contents/Resources/DWARF/interrupts_RR b/bin/interrupts_RR.dSYM/Contents/Resources/DWARF/interrupts_RR
new file mode 100644
index 0000000..95bbd44
Binary files /dev/null and b/bin/interrupts_RR.dSYM/Contents/Resources/DWARF/interrupts_RR differ
diff --git a/bin/interrupts_RR.dSYM/Contents/Resources/Relocations/x86_64/interrupts_RR.yml b/bin/interrupts_RR.dSYM/Contents/Resources/Relocations/x86_64/interrupts_RR.yml
new file mode 100644
index 0000000..94b0cf8
--- /dev/null
+++ b/bin/interrupts_RR.dSYM/Contents/Resources/Relocations/x86_64/interrupts_RR.yml
@@ -0,0 +1,5 @@
+---
+triple: 'x86_64-apple-darwin'
+binary-path: 'bin/interrupts_RR'
+relocations: []
+...
diff --git a/build.sh b/build.sh
index a101de3..25943be 100644
--- a/build.sh
+++ b/build.sh
@@ -4,6 +4,9 @@ else
rm bin/*
fi
-g++ -g -O0 -I . -o bin/interrupts_EP interrupts_student1_student2_EP.cpp
-g++ -g -O0 -I . -o bin/interrupts_RR interrupts_student1_student2_RR.cpp
-g++ -g -O0 -I . -o bin/interrupts_EP_RR interrupts_student1_student2_EP_RR.cpp
\ No newline at end of file
+#g++ -g -O0 -I . -o bin/interrupts_EP interrupts_student1_student2_EP.cpp
+#g++ -g -O0 -I . -o bin/interrupts_RR interrupts_student1_student2_RR.cpp
+g++ -g -O0 -I . -o bin/interrupts_EP_RR interrupts_student1_student2_EP_RR.cpp
+#./bin/interrupts_EP ./test1.txt
+#./bin/interrupts_RR ./test1.txt
+./bin/interrupts_EP_RR ./test1.txt
\ No newline at end of file
diff --git a/execution.txt b/execution.txt
new file mode 100644
index 0000000..c36b06f
--- /dev/null
+++ b/execution.txt
@@ -0,0 +1,38 @@
++------------------------------------------------+
+|Time of Transition |PID | Old State | New State |
++------------------------------------------------+
+| 0 |100 | NEW | READY |
+| 0 |100 | READY | RUNNING |
+| 50 | 10 | NEW | READY |
+| 50 |100 | RUNNING | READY |
+| 50 | 10 | READY | RUNNING |
+| 70 | 10 | RUNNING | WAITING |
+| 70 |100 | READY | RUNNING |
+| 120 | 10 | WAITING | READY |
+| 119 |100 | RUNNING | READY |
+| 119 | 10 | READY | RUNNING |
+| 139 | 10 | RUNNING | WAITING |
+| 139 |100 | READY | RUNNING |
+| 189 | 10 | WAITING | READY |
+| 188 |100 | RUNNING | READY |
+| 188 | 10 | READY | RUNNING |
+| 208 | 10 | RUNNING |TERMINATED |
+| 208 |100 | READY | RUNNING |
+| 308 |100 | RUNNING | READY |
+| 308 |100 | READY | RUNNING |
+| 408 |100 | RUNNING | READY |
+| 408 |100 | READY | RUNNING |
+| 508 |100 | RUNNING | READY |
+| 508 |100 | READY | RUNNING |
+| 608 |100 | RUNNING | READY |
+| 608 |100 | READY | RUNNING |
+| 708 |100 | RUNNING | READY |
+| 708 |100 | READY | RUNNING |
+| 808 |100 | RUNNING | READY |
+| 808 |100 | READY | RUNNING |
+| 908 |100 | RUNNING | READY |
+| 908 |100 | READY | RUNNING |
+| 1008 |100 | RUNNING | READY |
+| 1008 |100 | READY | RUNNING |
+| 1060 |100 | RUNNING |TERMINATED |
++------------------------------------------------+
diff --git a/interrupts_student1_student2 b/interrupts_student1_student2
new file mode 100644
index 0000000..3d02e7e
Binary files /dev/null and b/interrupts_student1_student2 differ
diff --git a/interrupts_student1_student2.hpp b/interrupts_student1_student2.hpp
index 99472fd..8c635fd 100644
--- a/interrupts_student1_student2.hpp
+++ b/interrupts_student1_student2.hpp
@@ -58,13 +58,17 @@ struct PCB{
int PID;
unsigned int size;
unsigned int arrival_time;
- int start_time;
+ int start_time; // time when process starts execution
unsigned int processing_time;
- unsigned int remaining_time;
+ unsigned int remaining_time; // cpu burst time, dont mix with remaining io time
int partition_number;
enum states state;
- unsigned int io_freq;
+ unsigned int io_freq; // frquenxy of io interrupts
unsigned int io_duration;
+
+ int remaining_io_time; // added for tracking remaining io time, wait time
+ int time_until_next_io; // added for tracking time until next io interrupt
+
};
//------------------------------------HELPER FUNCTIONS FOR THE SIMULATOR------------------------------
@@ -270,6 +274,9 @@ PCB add_process(std::vector tokens) {
process.partition_number = -1;
process.state = NOT_ASSIGNED;
+ process.remaining_io_time = 0; // initialize wait timer to 0
+ process.time_until_next_io = process.io_freq; // initialize burst timer to frequency
+
return process;
}
diff --git a/interrupts_student1_student2_EP.cpp b/interrupts_student1_student2_EP.cpp
index 784541a..a225739 100644
--- a/interrupts_student1_student2_EP.cpp
+++ b/interrupts_student1_student2_EP.cpp
@@ -63,11 +63,61 @@ std::tuple run_simulation(std
///////////////////////MANAGE WAIT QUEUE/////////////////////////
//This mainly involves keeping track of how long a process must remain in the ready queue
-
+ for (auto itr = wait_queue.begin(); itr != wait_queue.end();){
+ itr->remaining_io_time--; // decrement IO remaining time
+ if (itr->remaining_io_time == 0){
+ PCB process = *itr; // process for the completed IO
+
+ process.state = READY;
+ ready_queue.push_back(process); // add process to the ready queue
+
+ sync_queue(job_list, process); // syncing copy of the process state to the real process state
+ execution_status += print_exec_status(current_time, process.PID, WAITING, READY); // process went from waiting to ready
+ itr = wait_queue.erase(itr); // remove from wait queue
+ }
+ else{
+ ++itr;
+ }
+ }
/////////////////////////////////////////////////////////////////
//////////////////////////SCHEDULER//////////////////////////////
- FCFS(ready_queue); //example of FCFS is shown here
+ //FCFS(ready_queue); //example of FCFS is shown here
+ // asumption: lower pid = higher priority
+ if(running.PID == -1 && !ready_queue.empty()) { // handling empty CPU
+ run_process(running, job_list, ready_queue, current_time); // set new running process
+ execution_status += print_exec_status(current_time, running.PID, READY, RUNNING);
+ }
+
+ if (running.PID != -1){ // handling if there is a running process NO PREEMPTION
+
+ if(running.remaining_time == 0){ // handling when the process is finished
+ execution_status += print_exec_status(current_time, running.PID, RUNNING, TERMINATED);
+ terminate_process(running, job_list);
+ idle_CPU(running); // set CPU to idle
+
+ if(!ready_queue.empty()) { // checking if there is a ready process that can run
+ run_process(running, job_list, ready_queue, current_time);
+ execution_status += print_exec_status(current_time, running.PID, READY, RUNNING);
+ }
+ }
+
+ else if (running.io_freq > 0 && running.time_until_next_io == 0){ // handling IO interrupt
+ running.state = WAITING;
+ running.remaining_io_time = running.io_duration; // set remaining IO time for waiting
+ running.time_until_next_io = running.io_freq; // reset time until next IO interrupt
+
+ wait_queue.push_back(running); // add running process to wait queue
+ execution_status += print_exec_status(current_time, running.PID, RUNNING, WAITING);
+
+ idle_CPU(running);
+ }
+ running.remaining_time--; // decrement remaining time of running process
+ running.time_until_next_io--; // decrement time until next IO interrupt
+ sync_queue(job_list, running);
+ }
+
+ current_time++;
/////////////////////////////////////////////////////////////////
}
diff --git a/interrupts_student1_student2_EP_RR.cpp b/interrupts_student1_student2_EP_RR.cpp
index 784541a..a8bd067 100644
--- a/interrupts_student1_student2_EP_RR.cpp
+++ b/interrupts_student1_student2_EP_RR.cpp
@@ -27,6 +27,9 @@ std::tuple run_simulation(std
//to make the code easier :).
unsigned int current_time = 0;
+ int quantum_counter = 0;
+ const int TIME_QUANTUM = 100;
+
PCB running;
//Initialize an empty running process
@@ -63,11 +66,126 @@ std::tuple run_simulation(std
///////////////////////MANAGE WAIT QUEUE/////////////////////////
//This mainly involves keeping track of how long a process must remain in the ready queue
-
+ for (auto itr = wait_queue.begin(); itr != wait_queue.end();){ // same method approach as in EP and RR
+ itr->remaining_io_time--;
+
+ if (itr->remaining_io_time <= 0){
+ PCB process = *itr; // process for the completed IO
+
+ process.state = READY;
+ ready_queue.push_back(process); // add process to the ready queue
+
+ sync_queue(job_list, process); // syncing copy of the process state to the real process state
+ execution_status += print_exec_status(current_time + 1, process.PID, WAITING, READY); // process went from waiting to ready
+ itr = wait_queue.erase(itr); // remove from wait queue
+ }
+ else{
+ ++itr;
+ }
+ }
/////////////////////////////////////////////////////////////////
//////////////////////////SCHEDULER//////////////////////////////
- FCFS(ready_queue); //example of FCFS is shown here
+ //assumption: picking the next process with the lowest PID from the ready queue
+
+ if(ready_queue.size() > 1){ // using bubble sort!! to sort the lowest to highest PID (might be inefficient tho)
+ for(int i = 0; i < ready_queue.size() - 1; i++){
+ for(int j = 0; j < ready_queue.size() - i - 1; j++){
+ // Swap if Left is Smaller than Right (pushes Smallest to the Right/Back)
+ bool swap = false;
+ if (ready_queue[j].PID < ready_queue[j+1].PID) {
+ swap = true;
+ } else if (ready_queue[j].PID == ready_queue[j+1].PID) {
+ if (ready_queue[j].arrival_time < ready_queue[j+1].arrival_time) {
+ swap = true;
+ }
+ }
+ if (swap) {
+ PCB temp = ready_queue[j];
+ ready_queue[j] = ready_queue[j+1];
+ ready_queue[j+1] = temp;
+ }
+ }
+ }
+ }
+
+ if (running.PID != -1 && !ready_queue.empty()) { // handling busy CPU but other opocesses
+ PCB lower_PID = ready_queue.back(); // Now valid because we sorted above
+ if (lower_PID.PID < running.PID){ // preempt running process
+
+ running.state = READY;
+ ready_queue.push_back(running); // add running process to ready queue
+
+ sync_queue(job_list, running);
+ execution_status += print_exec_status(current_time, running.PID, RUNNING, READY);
+ idle_CPU(running);
+ quantum_counter = 0;
+ }
+ }
+
+ if (running.PID == -1 && !ready_queue.empty()) {
+ if(ready_queue.size() > 1){ // nunnle sprt again just in case some processes were added back to ready queue
+ for(int i = 0; i < ready_queue.size() - 1; i++){
+ for(int j = 0; j < ready_queue.size() - i - 1; j++){
+ bool swap = false;
+ if (ready_queue[j].PID < ready_queue[j+1].PID) {
+ swap = true;
+ } else if (ready_queue[j].PID == ready_queue[j+1].PID) {
+ if (ready_queue[j].arrival_time < ready_queue[j+1].arrival_time) {
+ swap = true;
+ }
+ }
+ if (swap) {
+ PCB temp = ready_queue[j];
+ ready_queue[j] = ready_queue[j+1];
+ ready_queue[j+1] = temp;
+ }
+ }
+ }
+ }
+
+ run_process(running, job_list, ready_queue, current_time);
+ quantum_counter = 0;
+ execution_status += print_exec_status(current_time, running.PID, READY, RUNNING);
+ }
+
+ if (running.PID != -1){ // taken from RR, handling if there is a running process
+ running.remaining_time--;
+ if(running.io_freq > 0) {
+ running.time_until_next_io--;
+ }
+ quantum_counter++;
+ sync_queue(job_list, running);
+
+ if(running.remaining_time <= 0){ // handling when the process is finished, taken from RR
+ execution_status += print_exec_status(current_time + 1, running.PID, RUNNING, TERMINATED);
+ terminate_process(running, job_list);
+ idle_CPU(running);
+ quantum_counter = 0; // reset quantum count
+ }
+
+ else if (running.io_freq > 0 && running.time_until_next_io <= 0){ // taken from EP, handling IO interrupt
+ running.state = WAITING;
+ running.remaining_io_time = running.io_duration;
+ running.time_until_next_io = running.io_freq;
+
+ wait_queue.push_back(running);
+ execution_status += print_exec_status(current_time + 1, running.PID, RUNNING, WAITING);
+
+ idle_CPU(running);
+ quantum_counter = 0;
+ }
+
+ else if (quantum_counter >= TIME_QUANTUM){ // handling if quantum time is over
+ running.state = READY;
+ ready_queue.push_back(running); // add running process to back of ready queue
+ execution_status += print_exec_status(current_time + 1, running.PID, RUNNING, READY);
+
+ idle_CPU(running);
+ quantum_counter = 0;
+ }
+ }
+ current_time++;
/////////////////////////////////////////////////////////////////
}
diff --git a/interrupts_student1_student2_RR.cpp b/interrupts_student1_student2_RR.cpp
index 784541a..9a8cf29 100644
--- a/interrupts_student1_student2_RR.cpp
+++ b/interrupts_student1_student2_RR.cpp
@@ -27,6 +27,9 @@ std::tuple run_simulation(std
//to make the code easier :).
unsigned int current_time = 0;
+ int quantum_counter = 0; //time quantum for RR scheduling
+ const int TIME_QUANTUM = 100; // define the time quantum
+
PCB running;
//Initialize an empty running process
@@ -63,12 +66,76 @@ std::tuple run_simulation(std
///////////////////////MANAGE WAIT QUEUE/////////////////////////
//This mainly involves keeping track of how long a process must remain in the ready queue
-
- /////////////////////////////////////////////////////////////////
+ for (auto itr = wait_queue.begin(); itr != wait_queue.end();){ // same method approach as in EP
+ itr->remaining_io_time--;
+
+ if (itr->remaining_io_time <= 0){
+ PCB process = *itr; // process for the completed IO
+
+ process.state = READY;
+ ready_queue.push_back(process); // add process to the ready queue
+
+ sync_queue(job_list, process); // syncing copy of the process state to the real process state
+ execution_status += print_exec_status(current_time + 1, process.PID, WAITING, READY); // process went from waiting to ready
+ itr = wait_queue.erase(itr); // remove from wait queue
+ }
+ else{
+ ++itr;
+ }
+ }
+ ///////////////////////////////////////////////////////////////
//////////////////////////SCHEDULER//////////////////////////////
- FCFS(ready_queue); //example of FCFS is shown here
- /////////////////////////////////////////////////////////////////
+ //assumption: picking the next process from the front of the ready queue
+ if (running.PID == -1 && !ready_queue.empty()) { // handling empty CPU
+ running = ready_queue.front();
+ ready_queue.erase(ready_queue.begin());
+ running.state = RUNNING;
+ running.start_time = current_time;
+ quantum_counter = 0; // reset quantum count
+ sync_queue(job_list, running);
+ execution_status += print_exec_status(current_time, running.PID, READY, RUNNING);
+ }
+
+ if(running.PID != -1){ // handling if there is a running process
+ running.remaining_time--; // decrement remaining time of running process
+ if(running.io_freq > 0) {
+ running.time_until_next_io--; // decrement IO timer
+ }
+ quantum_counter++; // increment quantum timer
+
+ sync_queue(job_list, running);
+
+ if(running.remaining_time <= 0){ // handling when the process is finished
+ execution_status += print_exec_status(current_time + 1, running.PID, RUNNING, TERMINATED);
+ terminate_process(running, job_list);
+ idle_CPU(running);
+ quantum_counter = 0; // reset quantum count
+ }
+
+ else if (running.io_freq > 0 && running.time_until_next_io <= 0){ // handling IO interrupt
+ running.state = WAITING;
+ running.remaining_io_time = running.io_duration; // set remaining IO time for waiting
+ running.time_until_next_io = running.io_freq; // reset time until next IO interrupt
+
+ wait_queue.push_back(running);
+ execution_status += print_exec_status(current_time + 1, running.PID, RUNNING, WAITING);
+
+ idle_CPU(running);
+ quantum_counter = 0;
+ }
+
+ else if (quantum_counter >= TIME_QUANTUM){ // handling if quantum time is over
+ running.state = READY;
+ ready_queue.push_back(running); // add running process to back of ready queue
+ execution_status += print_exec_status(current_time + 1, running.PID, RUNNING, READY);
+
+ idle_CPU(running);
+ quantum_counter = 0;
+ }
+ }
+ current_time++;
+ ///////////////////////////////////////////////////////////////
}
diff --git a/test1.txt b/test1.txt
new file mode 100644
index 0000000..47d474a
--- /dev/null
+++ b/test1.txt
@@ -0,0 +1,2 @@
+100, 1, 0, 1000, 0, 0
+10, 1, 50, 60, 20, 50
\ No newline at end of file