Finished with SJF Scheduling, minus one tiny bug. Otherwise, memory operations can be started on.

This commit is contained in:
Charles Descamps 2024-03-16 19:52:33 -07:00
parent 0b6d2d0b0c
commit eb87c7f9b9
3 changed files with 34 additions and 2 deletions

View file

@ -1,4 +1,4 @@
0.000001, OS: Simulator start
0.000000, OS: Simulator start
READY state from NEW state
ate

Binary file not shown.

View file

@ -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);