From 0cfc08f69d7882cced3185bb2927a5aaa76171a0 Mon Sep 17 00:00:00 2001 From: bakere1 <bakere1@student.unimelb.edu.au> Date: Sun, 28 Mar 2021 23:01:58 +1100 Subject: [PATCH] "RUNNING" log entries --- allocate.c | 150 ++++++----------------------------------------------- 1 file changed, 17 insertions(+), 133 deletions(-) diff --git a/allocate.c b/allocate.c index 9a2b2e3..d1567e4 100644 --- a/allocate.c +++ b/allocate.c @@ -129,17 +129,6 @@ int main(int argc, char *argv[]) { CPUs[j].totalExecutionTimeRemaining -= deltaTime; } } - // Log started processes. - for (int j = 0; j < numCPU; j++) { - headProcess = headData(CPUs[j].processQueue); - //next process in queue started - if (headProcess != NULL && headProcess->justStarted) { - // printf("current time: %d\n", currentTime); - headProcess->justStarted = 0; - printf("%d,RUNNING,pid=%s,remaining_time=%d,cpu=%d\n", - deltaTime+1, headProcess->processID, headProcess->timeRemaining, j); - } - } if (newProcess->parallelisable == 'n') { @@ -176,7 +165,6 @@ int main(int argc, char *argv[]) { parableProcess[i].timeCompleted = -1; parableProcess[i].timeRemaining = parableProcess[i].executionTime; addProcessToQueue(CPUs[i].processQueue, ¶bleProcess[i], currentTime, i); - } numProcessesLeft += 1; llist_push(paralellizedProcesses, newProcess); @@ -184,6 +172,17 @@ int main(int argc, char *argv[]) { printf("Error in test file "); exit(1); } + // Log started processes. + for (int j = 0; j < numCPU; j++) { + headProcess = headData(CPUs[j].processQueue); + //next process in queue started + if (headProcess != NULL && headProcess->justStarted) { + // printf("current time: %d\n", currentTime); + headProcess->justStarted = 0; + printf("%d,RUNNING,pid=%s,remaining_time=%d,cpu=%d\n", + deltaTime+1, headProcess->processID, headProcess->timeRemaining, j); + } + } } fclose(f); @@ -360,16 +359,9 @@ void advanceProcessQueue(llist *processQueue, int currentTime, int deltaTime, ll llist_pop(processQueue); headProcess = headData(processQueue); if (headProcess) headProcess->justStarted = -1; -/* //next process in queue started - if (headProcess != NULL) { - // printf("current time: %d\n", currentTime); - printf("%d,RUNNING,pid=%s,remaining_time=%d,cpu=%d\n", - currentTime-deltaTime, headProcess->processID, headProcess->timeRemaining, cpuID); - } - */ } else { // finishedprocess is not parallelisable + } else { // finishedprocess is not parallelisable *numProcessesLeft -= 1; *numProcessComplete += 1; - printf("%d,FINISHED,pid=%s,proc_remaining=%d\n", headProcess->timeCompleted, headProcess->processID, *numProcessesLeft); // Could accumulate statistics here instead of keeping list of completed processes @@ -377,13 +369,7 @@ void advanceProcessQueue(llist *processQueue, int currentTime, int deltaTime, ll llist_pop(processQueue); headProcess = headData(processQueue); if (headProcess) headProcess->justStarted = -1; -/* headProcess = headData(processQueue); - //next process in queue started - if (headProcess != NULL) { - printf("%d,RUNNING,pid=%s,remaining_time=%d,cpu=%d\n", - currentTime-deltaTime, headProcess->processID, headProcess->timeRemaining, cpuID); - } - */ } + } } else { // head process not finished headProcess->timeRemaining -= deltaTime; @@ -428,110 +414,8 @@ 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); -// -// } -} - -process *getNextProcess(FILE *f, llist *arrivals, process *readAhead) { - char line[36]; - - process *newProcess = malloc(sizeof(process)); - process *nextProcess = malloc(sizeof(process)); - process *headProcess; - - - if (arrivals == NULL) { - perror("list is NULL"); - return NULL; - } - - llist_print(arrivals,(void (*)(void *)) &printQEntry); - headProcess = headData(arrivals); - if (headProcess != NULL){//there are processes in arrivals - return llist_pop(arrivals); - } - - //checking if at the end of the file - 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); - llist_add_inorder(readAhead, arrivals, (int (*)(void *, void *)) &leastExecutionTime); - 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 NULL; - } - }else if(readAhead->timeArrived == -1 && headData(arrivals) != NULL ) { //have read EOF but still arrivals - return llist_pop(arrivals); - }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); - 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 - //memcpy(nextProcess,readAhead, sizeof(process)); - llist_add_inorder(readAhead, arrivals, (int (*)(void *, void *)) &leastExecutionTime); - llist_print(arrivals,(void (*)(void *)) &printQEntry); - printf("readAhead: %s\n", readAhead->processID); - printf("New Process: %s\n", newProcess->processID); - memcpy(readAhead,newProcess,sizeof(process)); - printf("in if\n"); - llist_print(arrivals,(void (*)(void *)) &printQEntry); - printf("readAhead: %s\n", readAhead->processID); - - int count = 0; - llist_print(arrivals, (void (*)(void *)) &printQEntry); - while (newProcess->timeArrived == readAhead->timeArrived ){ - //readAhead = nextProcess; - //memcpy(nextProcess,readAhead, sizeof(process)); - if(count > 0 && readAhead->timeArrived != -1){ - llist_add_inorder(readAhead, arrivals, (int (*)(void *, void *)) &leastExecutionTime); - memcpy(readAhead, newProcess, sizeof(process)); - printf("readAhead: %s\n", readAhead->processID); - } - - //EOF the file assign readAhead to null then return pop(arrivals) - if(fgets(line, sizeof line, f) == NULL){ - printf("in while, end of file\n"); - llist_print(arrivals,(void (*)(void *)) &printQEntry); - readAhead->timeArrived = -1; // Flag EOF - return llist_pop(arrivals); - } - initializeProcess(line,newProcess); - count =+1; - printf("New Process: %s\n", readAhead->processID); - } - -// 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 - - memcpy(nextProcess, readAhead, sizeof(process)); - memcpy(readAhead, newProcess, sizeof(process)); - - return nextProcess; - } - } - + if (strncmp(headProcess->processID, newProcess->processID, sizeof (newProcess->processID))) + headProcess->justStarted=-1; } @@ -539,7 +423,7 @@ process *getNextProcessB(FILE *f, llist *arrivals, process *readAhead) { char line[36]; process *newProcess; - int batchEnd; + int batchEnd=0; if (arrivals != NULL) { if (headData(arrivals) == NULL && readAhead->timeArrived != -1) {// no buffered processes so...{ @@ -566,6 +450,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