diff --git a/allocate.c b/allocate.c index e5bf25c5449921c5f9741119d4927256ed2c1a8a..96c1b2f89232c50bf460336725089acdd25f1c4d 100644 --- a/allocate.c +++ b/allocate.c @@ -104,7 +104,7 @@ int main(int argc, char *argv[]) { //while (fgets(line, sizeof line, f) != NULL) { while (newProcess = getNextProcess(f, arrivalLounge, readAhead)) { - printf("process id:%s process arrival time: %d\n", newProcess->processID, newProcess->timeArrived); + //printf("process id:%s process arrival time: %d\n", newProcess->processID, newProcess->timeArrived); deltaTime = newProcess->timeArrived - currentTime; @@ -186,7 +186,7 @@ int main(int argc, char *argv[]) { } // No more processes to be read in, just need to finish the ones in the queues - printf("No more processes to be read in\n"); + //printf("No more processes to be read in\n"); int tr; while (numProcessesLeft) { // find how big the next time step is - its the smallest of the times remaining on each queue's head process @@ -227,8 +227,8 @@ int main(int argc, char *argv[]) { // currentTime += deltaTime; } - printf("Completed Queue:"); - llist_print(completedProcesses, (void (*)(void *)) &printQEntry); +// printf("Completed Queue:"); +// llist_print(completedProcesses, (void (*)(void *)) &printQEntry); calStats(completedProcesses, ¤tTime, &averageTurnaroundTime, &maxOverhead, &averageOverhead); @@ -442,34 +442,35 @@ process *getNextProcess(FILE *f, llist *arrivals, process *readAhead) { if (arrivals == NULL) { perror("list is NULL"); + return NULL; } - if (headProcess !=NULL){ + headProcess = headData(arrivals); + if (headProcess != NULL){//thare are processes in arrivals return llist_pop(arrivals); } - //checking if at the end of the file - if (fgets(line, sizeof line, f) == NULL && readAhead != NULL ) { //read EOF && readAhead != NULL + if (fgets(line, sizeof line, f) == NULL && readAhead->timeArrived != -1 ) { //read EOF && readAhead != NULL memcpy(nextProcess,readAhead, sizeof(process)); llist_add_inorder(nextProcess, arrivals, (int (*)(void *, void *)) &leastExecutionTime); - readAhead = NULL; + readAhead->timeArrived = -1; + free(readAhead); //initializeProcess(NULL,readAhead); if (headData(arrivals) != NULL) { //have read EOF but still arrivals return llist_pop(arrivals); } else if (headData(arrivals) == NULL) { //have read EOF; all arrivals dealt with - return readAhead; + return NULL; } - } else if(readAhead == NULL && headData(arrivals) != NULL ) { //have read EOF but still arrivals + }else if(readAhead->timeArrived == -1 && headData(arrivals) != NULL ) { //have read EOF but still arrivals return llist_pop(arrivals); - }else if(readAhead == NULL && headData(arrivals) == NULL) { //have read EOF; all arrivals dealt with - return readAhead; + }else if(readAhead->timeArrived == -1 && headData(arrivals) == NULL) { //have read EOF; all arrivals dealt with + return NULL; }else{// Normal case initializeProcess(line, newProcess); } - - headProcess = headData(arrivals); + //headProcess = headData(arrivals); if(headProcess == NULL){//no one in the arrivals lounge //same start time if(newProcess->timeArrived == readAhead->timeArrived){ @@ -479,7 +480,7 @@ process *getNextProcess(FILE *f, llist *arrivals, process *readAhead) { readAhead = nextProcess; //EOF the file assign readAhead to null then return pop(arrivals) if(fgets(line, sizeof line, f) == NULL){ - readAhead = NULL; + readAhead->timeArrived = -1; return llist_pop(arrivals); } initializeProcess(line,newProcess); @@ -488,16 +489,13 @@ process *getNextProcess(FILE *f, llist *arrivals, process *readAhead) { readAhead = nextProcess; //if the readAhead is differnt return llist_pop(arrivals); - } else{//diff start time - // nextProcess = readAhead; + memcpy(nextProcess, readAhead, sizeof(process)); memcpy(readAhead, newProcess, sizeof(process)); - printf("Proc %s: Arrival: %d\n", nextProcess->processID, nextProcess->timeArrived); + return nextProcess; } - }else{//there are arrivals - return llist_pop(arrivals); }