diff --git a/allocate.c b/allocate.c index d16d58078eb6a88b7caf48aec4fc3a092e01a22e..9a2b2e3b5caafb2682aecbae4cc5b67edbd9c4d3 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