From 5918300b0d2213d522a18a335e25e6af3c374725 Mon Sep 17 00:00:00 2001 From: Bess <bakere1@student.unimelb.edu.au> Date: Sun, 28 Mar 2021 20:00:57 +1100 Subject: [PATCH] buffProc - for all --- allocate.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/allocate.c b/allocate.c index d16d580..9a2b2e3 100644 --- a/allocate.c +++ b/allocate.c @@ -1,7 +1,7 @@ /* * this is allocate.c */ - this is a confilict + #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -137,7 +137,7 @@ int main(int argc, char *argv[]) { // printf("current time: %d\n", currentTime); headProcess->justStarted = 0; printf("%d,RUNNING,pid=%s,remaining_time=%d,cpu=%d\n", - currentTime - deltaTime, headProcess->processID, headProcess->timeRemaining, j); + deltaTime+1, headProcess->processID, headProcess->timeRemaining, j); } } @@ -269,9 +269,10 @@ int leastTimeRemaining(process *p, process *q) { } int leastExecutionTime(process *p, process *q) { - if (p->executionTime < q->executionTime) - return -1; - else return 0; + if (p->executionTime < q->executionTime || p->executionTime == q->executionTime && + strcmp(p->processID, q->processID )) + return -1; //true + else return 0; //false } void initializeProcess(char data[], process *newProcess) { @@ -427,15 +428,15 @@ 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) { - printf("%d,RUNNING,pid=%s,remaining_time=%d,cpu=%d\n", - currentTime, newProcess->processID, newProcess->timeRemaining, cpuID); - } else if (oldProcess->processID != headProcess->processID && - oldProcess->timeRemaining != headProcess->timeRemaining) { - printf("%d,RUNNING,pid=%s,remaining_time=%d,cpu=%d\n", - currentTime, newProcess->processID, newProcess->timeRemaining, cpuID); - - } +// if (oldProcess == NULL) { +// printf("%d,RUNNING,pid=%s,remaining_time=%d,cpu=%d\n", +// currentTime, newProcess->processID, newProcess->timeRemaining, cpuID); +// } else if (oldProcess->processID != headProcess->processID && +// oldProcess->timeRemaining != headProcess->timeRemaining) { +// printf("%d,RUNNING,pid=%s,remaining_time=%d,cpu=%d\n", +// currentTime, newProcess->processID, newProcess->timeRemaining, cpuID); +// +// } } process *getNextProcess(FILE *f, llist *arrivals, process *readAhead) { @@ -556,6 +557,7 @@ process *getNextProcessB(FILE *f, llist *arrivals, process *readAhead) { } else { batchEnd = -1; memcpy(readAhead, newProcess, sizeof(process)); + free(newProcess); } } else { readAhead->timeArrived = -1; @@ -564,6 +566,6 @@ process *getNextProcessB(FILE *f, llist *arrivals, process *readAhead) { } // now there's stuff in the arrivals lounge or there are no more to arrive } - llist_print(arrivals, (void (*)(void *)) &printQEntry); + //llist_print(arrivals, (void (*)(void *)) &printQEntry); return llist_pop(arrivals); } \ No newline at end of file -- GitLab