From 14f8e877a039397b82e70e08a2a9f990ad1920e6 Mon Sep 17 00:00:00 2001
From: bakere1 <bakere1@student.unimelb.edu.au>
Date: Mon, 29 Mar 2021 13:32:41 +1100
Subject: [PATCH] Sub proc execution times rounded up. Trying to fix procs
 remaining.

---
 allocate.c | 28 +++++++++++++++++++---------
 1 file changed, 19 insertions(+), 9 deletions(-)

diff --git a/allocate.c b/allocate.c
index 6548d08..d7ef5f3 100644
--- a/allocate.c
+++ b/allocate.c
@@ -174,6 +174,18 @@ int main(int argc, char *argv[]) {
                 printf("Error in test file ");
                 exit(1);
             }
+            //  Log finished processes.
+            struct node * currNode  = (struct node *) completedProcesses;
+            process * currProc = currNode->data;
+            while ( currNode ){
+                if ( currProc->timeCompleted >= currentTime ) {
+                    printf("%d,FINISHED,pid=%s,proc_remaining=%d\n",
+                           currProc->timeCompleted, currProc->processID, numProcessesLeft);
+
+                }
+                currNode = currNode->next;
+                if (currNode) currProc = currNode->data;
+            }
             //  Log started processes.
             for (int j = 0; j < numCPU; j++) {
                 headProcess = headData(CPUs[j].processQueue);
@@ -313,13 +325,13 @@ process *headData(llist *q) {
 }
 
 process *parallelParent(llist *q, char *parentPid) {
-    struct node *head = *q;
+    struct node *curr = *q;
     process *p;
 
-    if (head) p = head->data;
-    while (head && !strncmp(p->processID, parentPid, strlen(parentPid))) {
-        head = head->next;
-        p = head->data;
+    if (curr) p = curr->data;
+    while (curr && !strncmp(p->processID, parentPid, strlen(parentPid))) {
+        curr = curr->next;
+        p = curr->data;
     }
     return p;
 }
@@ -355,10 +367,8 @@ void advanceProcessQueue(llist *processQueue, int currentTime, int deltaTime, ll
                     paralizedProcess->timeRemaining = 0;
                     headProcess->timeRemaining = 0;
                     //printf("process had finished: Current time: %d, deltaTime: %d\n", currentTime, deltaTime);
-                    printf("%d,FINISHED,pid=%s,proc_remaining=%d\n",
-                           paralizedProcess->timeCompleted, paralizedProcess->processID, *numProcessesLeft);
-                    //  Could accumulate statistics here instead of keeping list of completed processes
-                    llist_push(processesComplete, paralizedProcess);
+//                    //  Could accumulate statistics here instead of keeping list of completed processes
+//                    llist_push(processesComplete, paralizedProcess);
                 }
                 llist_pop(processQueue);
                 headProcess = headData(processQueue);
-- 
GitLab