From aa7d11bc81e5c3e132bd7e378e4a1def3e015d24 Mon Sep 17 00:00:00 2001
From: Bess <bakere1@student.unimelb.edu.au>
Date: Mon, 29 Mar 2021 01:36:30 +1100
Subject: [PATCH] compare diff

---
 allocate.c | 41 ++++++++++++++++++++++++-----------------
 1 file changed, 24 insertions(+), 17 deletions(-)

diff --git a/allocate.c b/allocate.c
index b383ca3..6e01e5e 100644
--- a/allocate.c
+++ b/allocate.c
@@ -20,7 +20,7 @@ typedef struct {
     int timeRemaining;
     int subProcsRunning;
     int justStarted;
-    int startTime;
+    int deltaTime;
 } process;
 
 typedef struct {
@@ -111,7 +111,11 @@ int main(int argc, char *argv[]) {
 
         //while (fgets(line, sizeof line, f) != NULL) {
         while (newProcess = getNextProcessB(f, arrivalLounge, readAhead)) {
+
+            //printf("process id:%s  process arrival time: %d\n", newProcess->processID, newProcess->timeArrived);
+
             deltaTime = newProcess->timeArrived - currentTime;
+
             //update currentTime
             currentTime += deltaTime;
 
@@ -160,11 +164,14 @@ int main(int argc, char *argv[]) {
                     parableProcess[i].parallelisable = newProcess->parallelisable;
                     parableProcess[i].timeCompleted = -1;
                     parableProcess[i].timeRemaining = parableProcess[i].executionTime;
-                    parableProcess[i].startTime = newProcess->startTime;
+                    parableProcess[i].deltaTime = newProcess->deltaTime;
                     addProcessToQueue(CPUs[i].processQueue, &parableProcess[i], currentTime, i);
                 }
                 numProcessesLeft += 1;
                 llist_push(paralellizedProcesses, newProcess);
+            } else {
+                printf("Error in test file ");
+                exit(1);
             }
             //  Log started processes.
             for (int j = 0; j < numCPU; j++) {
@@ -172,9 +179,10 @@ 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->timeRemaining, 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);
                 }
             }
 
@@ -218,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);
-                printf("%d,RUNNING,pid=%s,remaining_time=%d,cpu=%d\n",
-                       headProcess->startTime, headProcess->processID, headProcess->timeRemaining, j);
                 headProcess->justStarted = 0;
+                printf("%d,RUNNING,pid=%s,remaining_time=%d,cpu=%d\n",
+                       currentTime, headProcess->processID, headProcess->timeRemaining, j);
             }
         }
 
@@ -288,10 +296,10 @@ void initializeProcess(char data[], process *newProcess) {
     if (token != NULL) {
         newProcess->parallelisable = token[0];
     }
-    newProcess->startTime = 0;
+    newProcess->deltaTime =0;
+    newProcess->justStarted =0;
     newProcess->timeCompleted = -1;
     newProcess->timeRemaining = newProcess->executionTime;
-    newProcess->justStarted = 0;
 }
 
 process *headData(llist *q) {
@@ -329,11 +337,12 @@ void advanceProcessQueue(llist *processQueue, int currentTime, int deltaTime, ll
     while (headProcess != NULL && deltaTime != 0) {
         if (deltaTime >= headProcess->timeRemaining) {  //  Process has finished
             deltaTime -= headProcess->timeRemaining;
-            headProcess->timeCompleted = currentTime - deltaTime;
+            headProcess->timeCompleted = currentTime - deltaTime; //+ headProcess->timeRemaining;
+//            int t = headProcess->timeRemaining;
             headProcess->timeRemaining = 0;
             if (headProcess->parallelisable == 'p') {
                 //printf("process had finished, and was a paralized subprocess\n");
-                parentPid[0] = strtok(headProcess->processID, ".");
+                parentPid[0] = strtok(headProcess->processID, ".");//todo to get rid of warning strncopy
                 paralizedProcess = parallelParent(paralellProcesses, parentPid);
                 paralizedProcess->subProcsRunning -= 1;
                 if (paralizedProcess->subProcsRunning == 0) {
@@ -354,7 +363,7 @@ void advanceProcessQueue(llist *processQueue, int currentTime, int deltaTime, ll
                 headProcess = headData(processQueue);
                 if (headProcess){
                     headProcess->justStarted = -1;
-                    headProcess->startTime = currentTime - deltaTime;
+                    headProcess->deltaTime = deltaTime;
                 }
 
             } else { // finishedprocess is not parallelisable
@@ -368,12 +377,13 @@ void advanceProcessQueue(llist *processQueue, int currentTime, int deltaTime, ll
                 headProcess = headData(processQueue);
                 if (headProcess){
                     headProcess->justStarted = -1;
-                    headProcess->startTime = currentTime - deltaTime;
+                    headProcess->deltaTime = deltaTime;
                 }
             }
 
         } else { // head process not finished
             headProcess->timeRemaining -= deltaTime;
+            headProcess->deltaTime = deltaTime;
             deltaTime = 0;
             // llist_print( processQueue, (void (*)(void *)) &printQEntry );
         }
@@ -414,11 +424,8 @@ void addProcessToQueue(llist *processQueue, process *newProcess, int currentTime
     process *headProcess;
     llist_add_inorder(newProcess, processQueue, (int (*)(void *, void *)) &leastTimeRemaining);
     headProcess = headData(processQueue);
-//    llist_print(processQueue, (void (*)(void *)) &printQEntry);
-    if (!strncmp(headProcess->processID, newProcess->processID, sizeof (newProcess->processID))) {
-        headProcess->justStarted = -1;
-        headProcess->startTime = currentTime;
-    }
+    if ( oldProcess != NULL &&  !strncmp(headProcess->processID, oldProcess->processID, sizeof (newProcess->processID)) )
+        headProcess->justStarted=-1;
 
 }
 
-- 
GitLab