Skip to content
Snippets Groups Projects
Commit 2ff27b06 authored by Elizabeth Baker's avatar Elizabeth Baker
Browse files

buffProc - working

parent b1c1e252
No related branches found
No related tags found
No related merge requests found
...@@ -104,7 +104,7 @@ int main(int argc, char *argv[]) { ...@@ -104,7 +104,7 @@ int main(int argc, char *argv[]) {
//while (fgets(line, sizeof line, f) != NULL) { //while (fgets(line, sizeof line, f) != NULL) {
while (newProcess = getNextProcess(f, arrivalLounge, readAhead)) { 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; deltaTime = newProcess->timeArrived - currentTime;
...@@ -186,7 +186,7 @@ int main(int argc, char *argv[]) { ...@@ -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 // 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; int tr;
while (numProcessesLeft) { while (numProcessesLeft) {
// find how big the next time step is - its the smallest of the times remaining on each queue's head process // 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[]) { ...@@ -227,8 +227,8 @@ int main(int argc, char *argv[]) {
// currentTime += deltaTime; // currentTime += deltaTime;
} }
printf("Completed Queue:"); // printf("Completed Queue:");
llist_print(completedProcesses, (void (*)(void *)) &printQEntry); // llist_print(completedProcesses, (void (*)(void *)) &printQEntry);
calStats(completedProcesses, &currentTime, &averageTurnaroundTime, &maxOverhead, &averageOverhead); calStats(completedProcesses, &currentTime, &averageTurnaroundTime, &maxOverhead, &averageOverhead);
...@@ -442,34 +442,35 @@ process *getNextProcess(FILE *f, llist *arrivals, process *readAhead) { ...@@ -442,34 +442,35 @@ process *getNextProcess(FILE *f, llist *arrivals, process *readAhead) {
if (arrivals == NULL) { if (arrivals == NULL) {
perror("list is 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); return llist_pop(arrivals);
} }
//checking if at the end of the file //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)); memcpy(nextProcess,readAhead, sizeof(process));
llist_add_inorder(nextProcess, arrivals, (int (*)(void *, void *)) &leastExecutionTime); llist_add_inorder(nextProcess, arrivals, (int (*)(void *, void *)) &leastExecutionTime);
readAhead = NULL; readAhead->timeArrived = -1;
free(readAhead);
//initializeProcess(NULL,readAhead); //initializeProcess(NULL,readAhead);
if (headData(arrivals) != NULL) { //have read EOF but still arrivals if (headData(arrivals) != NULL) { //have read EOF but still arrivals
return llist_pop(arrivals); return llist_pop(arrivals);
} else if (headData(arrivals) == NULL) { //have read EOF; all arrivals dealt with } 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); return llist_pop(arrivals);
}else if(readAhead == NULL && headData(arrivals) == NULL) { //have read EOF; all arrivals dealt with }else if(readAhead->timeArrived == -1 && headData(arrivals) == NULL) { //have read EOF; all arrivals dealt with
return readAhead; return NULL;
}else{// Normal case }else{// Normal case
initializeProcess(line, newProcess); initializeProcess(line, newProcess);
} }
//headProcess = headData(arrivals);
headProcess = headData(arrivals);
if(headProcess == NULL){//no one in the arrivals lounge if(headProcess == NULL){//no one in the arrivals lounge
//same start time //same start time
if(newProcess->timeArrived == readAhead->timeArrived){ if(newProcess->timeArrived == readAhead->timeArrived){
...@@ -479,7 +480,7 @@ process *getNextProcess(FILE *f, llist *arrivals, process *readAhead) { ...@@ -479,7 +480,7 @@ process *getNextProcess(FILE *f, llist *arrivals, process *readAhead) {
readAhead = nextProcess; readAhead = nextProcess;
//EOF the file assign readAhead to null then return pop(arrivals) //EOF the file assign readAhead to null then return pop(arrivals)
if(fgets(line, sizeof line, f) == NULL){ if(fgets(line, sizeof line, f) == NULL){
readAhead = NULL; readAhead->timeArrived = -1;
return llist_pop(arrivals); return llist_pop(arrivals);
} }
initializeProcess(line,newProcess); initializeProcess(line,newProcess);
...@@ -488,16 +489,13 @@ process *getNextProcess(FILE *f, llist *arrivals, process *readAhead) { ...@@ -488,16 +489,13 @@ process *getNextProcess(FILE *f, llist *arrivals, process *readAhead) {
readAhead = nextProcess; readAhead = nextProcess;
//if the readAhead is differnt //if the readAhead is differnt
return llist_pop(arrivals); return llist_pop(arrivals);
} else{//diff start time } else{//diff start time
// nextProcess = readAhead;
memcpy(nextProcess, readAhead, sizeof(process)); memcpy(nextProcess, readAhead, sizeof(process));
memcpy(readAhead, newProcess, sizeof(process)); memcpy(readAhead, newProcess, sizeof(process));
printf("Proc %s: Arrival: %d\n", nextProcess->processID, nextProcess->timeArrived);
return nextProcess; return nextProcess;
} }
}else{//there are arrivals
return llist_pop(arrivals);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment