diff --git a/allocate.c b/allocate.c index 96c1b2f89232c50bf460336725089acdd25f1c4d..f2b644d5d1476e579c25a2c1fd6cf38b960be2a1 100644 --- a/allocate.c +++ b/allocate.c @@ -9,6 +9,8 @@ #include "llist.c" #include "llist.h" +#define INT_MAX __INT_MAX__ + typedef struct { int timeArrived; int timeCompleted; //instant of time completed @@ -221,7 +223,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); + currentTime, headProcess->processID, headProcess->timeRemaining, j); } } @@ -455,7 +457,7 @@ process *getNextProcess(FILE *f, llist *arrivals, process *readAhead) { memcpy(nextProcess,readAhead, sizeof(process)); llist_add_inorder(nextProcess, arrivals, (int (*)(void *, void *)) &leastExecutionTime); readAhead->timeArrived = -1; - free(readAhead); + //free(readAhead); //initializeProcess(NULL,readAhead); if (headData(arrivals) != NULL) { //have read EOF but still arrivals return llist_pop(arrivals); @@ -474,19 +476,31 @@ process *getNextProcess(FILE *f, llist *arrivals, process *readAhead) { if(headProcess == NULL){//no one in the arrivals lounge //same start time if(newProcess->timeArrived == readAhead->timeArrived){ - //add to arrivals until the readAhead is different + //add to arrivals until the readAhead is different + //memcpy(nextProcess,readAhead, sizeof(process)); llist_add_inorder(readAhead, arrivals, (int (*)(void *, void *)) &leastExecutionTime); - while (newProcess->timeArrived == readAhead->timeArrived){ - readAhead = nextProcess; + memcpy(readAhead,newProcess,sizeof(process)); + int count = 0; + while (newProcess->timeArrived == readAhead->timeArrived ){ + //readAhead = nextProcess; + //memcpy(nextProcess,readAhead, sizeof(process)); + if(count > 0){ + llist_add_inorder(readAhead, arrivals, (int (*)(void *, void *)) &leastExecutionTime); + memcpy(readAhead, newProcess, sizeof(process)); + } + //EOF the file assign readAhead to null then return pop(arrivals) if(fgets(line, sizeof line, f) == NULL){ readAhead->timeArrived = -1; return llist_pop(arrivals); } initializeProcess(line,newProcess); - llist_add_inorder(readAhead, arrivals, (int (*)(void *, void *)) &leastExecutionTime); + count +1; } - readAhead = nextProcess; + llist_print(arrivals, (void (*)(void *)) &printQEntry); + + //readAhead = nextProcess; + memcpy(readAhead,nextProcess,sizeof(process)); //if the readAhead is differnt return llist_pop(arrivals); } else{//diff start time