From c5c8cb5fc2ec162bde34f253775a7111a0516874 Mon Sep 17 00:00:00 2001
From: bakere1 <bakere1@student.unimelb.edu.au>
Date: Mon, 29 Mar 2021 22:43:04 +1100
Subject: [PATCH] Log Process finishes within delta time

---
 allocate.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/allocate.c b/allocate.c
index 9d26980..8a8fdf4 100644
--- a/allocate.c
+++ b/allocate.c
@@ -22,6 +22,7 @@ typedef struct {
     int justStarted;
     int startTime;
     int timeRemAtStartTime;
+    int finished;
 } process;
 
 typedef struct {
@@ -182,9 +183,10 @@ int main(int argc, char *argv[]) {
             headData(completedProcesses);
             process * currProc = currNode->data;
             while ( currNode ){
-                if ( currProc!= NULL &&  currProc->timeCompleted >= currentTime  ) {
+                if ( currProc!= NULL &&  currProc->timeCompleted <= currentTime   && !currProc->finished) {
                     printf("%d,FINISHED,pid=%s,proc_remaining=%d\n",
                            currProc->timeCompleted, currProc->processID, numProcessesLeft);
+                    currProc->finished = -1;
                 }
                 currNode = currNode->next;
                 if (currNode) currProc = currNode->data;
@@ -240,9 +242,10 @@ int main(int argc, char *argv[]) {
         headData(completedProcesses);
         process * currProc = currNode->data;
         while ( currNode ){
-            if ( currProc!= NULL &&  currProc->timeCompleted >= currentTime  ) {
+            if ( currProc!= NULL &&  currProc->timeCompleted >= currentTime  && currProc->finished ) {
                 printf("%d,FINISHED,pid=%s,proc_remaining=%d\n",
                        currProc->timeCompleted, currProc->processID, numProcessesLeft);
+                currProc->finished = -1;
             }
             currNode = currNode->next;
             if (currNode) currProc = currNode->data;
@@ -360,6 +363,7 @@ void initializeProcess(char data[], process *newProcess) {
     newProcess->timeRemaining = newProcess->executionTime;
     newProcess->timeRemAtStartTime = newProcess->timeRemaining;
     newProcess->justStarted = 0;
+    newProcess->finished = 0;
 }
 
 process *headData(llist *q) {
-- 
GitLab