From 90b2e89e52daf33f6b8b137c48191936aa929d4f Mon Sep 17 00:00:00 2001
From: Bess <bakere1@student.unimelb.edu.au>
Date: Mon, 29 Mar 2021 12:42:25 +1100
Subject: [PATCH] bug 2) fixed

---
 allocate.c | 33 ++++++++++++++++++---------------
 1 file changed, 18 insertions(+), 15 deletions(-)

diff --git a/allocate.c b/allocate.c
index 6e01e5e..6548d08 100644
--- a/allocate.c
+++ b/allocate.c
@@ -20,7 +20,8 @@ typedef struct {
     int timeRemaining;
     int subProcsRunning;
     int justStarted;
-    int deltaTime;
+    int startTime;
+    int timeRemAtStartTime;
 } process;
 
 typedef struct {
@@ -164,7 +165,7 @@ int main(int argc, char *argv[]) {
                     parableProcess[i].parallelisable = newProcess->parallelisable;
                     parableProcess[i].timeCompleted = -1;
                     parableProcess[i].timeRemaining = parableProcess[i].executionTime;
-                    parableProcess[i].deltaTime = newProcess->deltaTime;
+                    parableProcess[i].timeRemAtStartTime = newProcess->timeRemAtStartTime;
                     addProcessToQueue(CPUs[i].processQueue, &parableProcess[i], currentTime, i);
                 }
                 numProcessesLeft += 1;
@@ -179,10 +180,9 @@ int main(int argc, char *argv[]) {
                 //next process in queue started
                 if (headProcess != NULL && headProcess->justStarted) {
                     // printf("current time: %d\n", currentTime);
+                    printf("%d,RUNNING,pid=%s,remaining_time=%d,cpu=%d\n",
+                           headProcess->startTime, headProcess->processID, headProcess->timeRemAtStartTime , j);
                     headProcess->justStarted = 0;
-                    printf("%d,RUNNING,pid=%s,remaining_time=%d,cpu=%d - AAAA line 184\n",
-                          currentTime - headProcess->deltaTime, headProcess->processID,
-                          headProcess->timeRemaining + headProcess->deltaTime, j);
                 }
             }
 
@@ -226,9 +226,9 @@ int main(int argc, char *argv[]) {
             //next process in queue started
             if (headProcess != NULL && headProcess->justStarted) {
                 // printf("current time: %d\n", currentTime);
-                headProcess->justStarted = 0;
                 printf("%d,RUNNING,pid=%s,remaining_time=%d,cpu=%d\n",
-                       currentTime, headProcess->processID, headProcess->timeRemaining, j);
+                       headProcess->startTime, headProcess->processID, headProcess->timeRemaining, j);
+                headProcess->justStarted = 0;
             }
         }
 
@@ -296,10 +296,11 @@ void initializeProcess(char data[], process *newProcess) {
     if (token != NULL) {
         newProcess->parallelisable = token[0];
     }
-    newProcess->deltaTime =0;
-    newProcess->justStarted =0;
+    newProcess->startTime = 0;
     newProcess->timeCompleted = -1;
     newProcess->timeRemaining = newProcess->executionTime;
+    newProcess->timeRemAtStartTime = newProcess->timeRemaining;
+    newProcess->justStarted = 0;
 }
 
 process *headData(llist *q) {
@@ -363,7 +364,8 @@ void advanceProcessQueue(llist *processQueue, int currentTime, int deltaTime, ll
                 headProcess = headData(processQueue);
                 if (headProcess){
                     headProcess->justStarted = -1;
-                    headProcess->deltaTime = deltaTime;
+                    headProcess->startTime = currentTime - deltaTime;
+                    headProcess->timeRemAtStartTime = headProcess->timeRemaining;
                 }
 
             } else { // finishedprocess is not parallelisable
@@ -377,13 +379,13 @@ void advanceProcessQueue(llist *processQueue, int currentTime, int deltaTime, ll
                 headProcess = headData(processQueue);
                 if (headProcess){
                     headProcess->justStarted = -1;
-                    headProcess->deltaTime = deltaTime;
+                    headProcess->startTime = currentTime - deltaTime;
                 }
             }
 
         } else { // head process not finished
             headProcess->timeRemaining -= deltaTime;
-            headProcess->deltaTime = deltaTime;
+//            headProcess->deltaTime = deltaTime;
             deltaTime = 0;
             // llist_print( processQueue, (void (*)(void *)) &printQEntry );
         }
@@ -424,9 +426,10 @@ void addProcessToQueue(llist *processQueue, process *newProcess, int currentTime
     process *headProcess;
     llist_add_inorder(newProcess, processQueue, (int (*)(void *, void *)) &leastTimeRemaining);
     headProcess = headData(processQueue);
-    if ( oldProcess != NULL &&  !strncmp(headProcess->processID, oldProcess->processID, sizeof (newProcess->processID)) )
-        headProcess->justStarted=-1;
-
+    if ( !strncmp(headProcess->processID, newProcess->processID, sizeof (newProcess->processID)) ) {
+        headProcess->justStarted = -1;
+        headProcess->startTime = currentTime;
+    }
 }
 
 process *getNextProcessB(FILE *f, llist *arrivals, process *readAhead) {
-- 
GitLab