diff --git a/Sim03/logfile_1.lgf b/Sim03/logfile_1.lgf index 0a374fe..52b0e91 100644 --- a/Sim03/logfile_1.lgf +++ b/Sim03/logfile_1.lgf @@ -1,4 +1,4 @@ -0.000001, OS: Simulator start +0.000000, OS: Simulator start READY state from NEW state ate diff --git a/Sim03/sim03 b/Sim03/sim03 index 2cba591..562b3c6 100755 Binary files a/Sim03/sim03 and b/Sim03/sim03 differ diff --git a/Sim03/simulator.c b/Sim03/simulator.c index d913f97..4500144 100644 --- a/Sim03/simulator.c +++ b/Sim03/simulator.c @@ -495,7 +495,10 @@ void runSim(ConfigDataType *configPtr, OpCodeType *metaDataMstrPtr) { while (pcbPtr != NULL) { - if (pcbPtr->uniquePid == currentPid) + // printf("Current Process Number is: %d\n", pcbPtr->uniquePid); + // printf("Process Status is: %d\n", pcbPtr->process_state); + // printf("Scheduled Process is: %d\n", currentPid); + if (pcbPtr->process_state != PROCESS_STATE_TERMINATED && pcbPtr->uniquePid == currentPid) { // needs to set from READY to RUNNING pcbPtr->process_state = PROCESS_STATE_RUNNING; @@ -547,6 +550,19 @@ int scheduleProcess(ProcessControlBlockLL *headPointer, ConfigDataType *configPt wkgPtr = headPointer->headPtr; char loggingStr[MAX_STR_LEN]; char timeStringy[MAX_STR_LEN]; + int processCount = 0; + + while (wkgPtr != NULL) + { + if(wkgPtr->process_state != PROCESS_STATE_TERMINATED) + { + // + processCount = processCount + 1; + } + wkgPtr = wkgPtr->nextPtr; + } + wkgPtr = headPointer->headPtr; + // switch case for each scheduling algorithm switch (configPtr->cpuSchedCode) { @@ -640,6 +656,22 @@ int scheduleProcess(ProcessControlBlockLL *headPointer, ConfigDataType *configPt // move to next pointer wkgPtr = wkgPtr->nextPtr; } + // check the number of processes, if there is one left, then + wkgPtr = headPointer->headPtr; + if(processCount == 1) + { + // find the last process that is READY but not TERMINATED, set it's PID as the return. + while(wkgPtr != NULL) + { + // + if (wkgPtr->process_state != PROCESS_STATE_TERMINATED) + { + // + shortestJobProcNum = wkgPtr->uniquePid; + } + wkgPtr = wkgPtr->nextPtr; + } + } // printf("Process %d Selected with %.0f ms remaining\n", wkgPtr->uniquePid, wkgPtr->timeLeft); sprintf(loggingStr, "%f, OS: Process %d selected with %.0f ms remaining\n", accessTimer(LAP_TIMER, timeStringy), shortestJobProcNum, (double)shortestJob); logOutput(configPtr, loggingStr, false);