diff options
Diffstat (limited to 'task-1-29994705.c')
| -rw-r--r-- | task-1-29994705.c | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/task-1-29994705.c b/task-1-29994705.c index 5766eae..2feeecc 100644 --- a/task-1-29994705.c +++ b/task-1-29994705.c @@ -6,7 +6,7 @@ * Alexander Occhipinti * Student ID: 29994705 * Created: 14 Oct 2020 - * Modified: 15 Oct 2020 + * Modified: 19 Oct 2020 * * This is the source file for Task 1 of Assignment 2. * This program simulates a FCFS (first-come-first-serve) scheduler with at most 10 simulated processes. @@ -104,6 +104,28 @@ void export_results(pcb_t *pcb_array, int num_pcbs) { } /* + * Scan through an array of PCBs and given a time, sets those that are due to enter the system to READY. + * Intended to simulate processes in the system being started while the scheduler is running. + * + * Args: + * pcb_array: an array of PCBs (pcb_t) to search through + * num_pcbs: the number of PCBs in the array provided + * time: the current unit of time that the scheduler is up to. +*/ +int scan_ready_procs(pcb_t *pcb_array, int num_pcbs, int time){ + int total_ready = 0; + for (int i = 0; i < num_pcbs; i++) { + if (pcb_array[i].entryTime <= time && pcb_array[i].state == UNENTERED) { + pcb_array[i].state = READY; + total_ready++; + printf("Time %d: Process %s entered the system.\n", time, pcb_array[i].process_name); + } + } + return total_ready; +} + + +/* * The function that runs the main FCFS scheduling simulation loop, provided an array of process PCBs to simulate. * Each loop represents a single unit of time, where processes may either be become ready, start running or finish. * For each unit of time, the following happens (in order): @@ -130,12 +152,7 @@ void perform_fcfs_scheduling(pcb_t *pcb_array, int num_pcbs) { next_process = &pcb_array[procs_done]; // Set the next_process pointer to the process to be worked on /* Go through each PCB and mark the ones that are ready as ready */ - for (int i = 0; i < num_pcbs; i++) { - if (pcb_array[i].entryTime <= time && pcb_array[i].state == UNENTERED) { - pcb_array[i].state = READY; - printf("Time %d: Process %s entered the system.\n", time, pcb_array[i].process_name); - } - } + scan_ready_procs(pcb_array, num_pcbs, time); // Scan and mark processes that are now ready as 'READY' /* Checks if the current process has completed, sets its status to EXIT if so */ if (next_process->state == RUNNING) { |
