ENES BAŞER - 2020400141
The main.c
file contains the main logic for a process scheduling simulation. It reads process data from a file, populates the process instructions, sorts the processes, and then simulates their execution.
-
Process
: Holding fields for processes. It would be a good choice to operaitons with fields of corresponding structs. -
Instruction
: Instruction has some fields like duration name. And also it is useful to use this structure inProcess
struct -
enum
: Defined for purpose of type of the process wheter they areGOLD,PLATINUM ,SILVER
-
procs
: An array ofProc
structures, each representing a process to be scheduled. -
count
: A counter for the number of processes read from the file. -
curr_time
: The current time in the simulation. -
turnaround
: A variable to hold the turnaround time. -
allFinished
: A boolean flag to check if all processes have finished execution. -
test
,temp_count
,init
: Temporary variables used in the simulation loop.
-
populateProcessInstructions(&procs[i])
: Populates the instructions for the processprocs[i]
. -
qsort(procs, count, sizeof(struct Proc), compareProcs)
: Sorts theprocs
array using thecompareProcs
function. -
compareProcs
: A function used to compare twoProc
structures (not shown in the provided code).
-
The program reads process data from a file and stores it in the
procs
array. If more than 10 processes are read, the program only keeps the first 10 and discards the rest. -
The program populates the instructions for each process.
-
The
procs
array is sorted to handle scheduling priority . (Refretence to qsort and custom compareTo function) -
The program enters a simulation loop where it simulates the execution of the processes. It handles types(defined as enum reference to
enum
) priorities, preemption , burst time for each of the process structures. -
At the end of the simulation if all process
isFinished
then exit loop and printturnaround time
andwaiting time
.
-
make
-
./scheduler
-
Test with different input changing to input file as
defX.txt
.