1
0

added base for FCFS algorithm

This commit is contained in:
Louis Heredero 2024-10-08 14:14:31 +02:00
parent 4a0e1d3209
commit 7120fe0509
Signed by: HEL
GPG Key ID: 8D83DE470F8544E7
2 changed files with 90 additions and 0 deletions

4
execution_example.csv Normal file
View File

@ -0,0 +1,4 @@
1 10 0 0
2 103 3 0
3 108 96 0
...
1 1 10 0 0
2 2 103 3 0
3 3 108 96 0
4 ...

View File

@ -1,8 +1,94 @@
#include <stdlib.h>
#include <stdio.h>
#define RR_QUANTUM 2
#define CNTXT_SWITCH 1
enum pstate {
WAITING,
READY,
FINISHED
};
struct pinfo {
int id;
int arrival_time;
int execution_time;
int priority;
int wait_time;
int completion_time;
enum pstate state;
struct pinfo * next_pinfo;
};
struct perf_info {
int total_time;
int total_nr_ctxt_switch;
int total_time_ctxt_switch;
};
struct pinfo * create_process(int id, int arrival_time, int execution_time, int priority) {
struct pinfo * info = {
id,
arrival_time,
execution_time,
priority,
0,
0,
WAITING,
NULL
};
return info;
}
struct perf_info * schedule_FCFS(struct pinfo * processes) {
int current_time = 0;
struct pinfo * process = processes;
struct perf_info * perf = {0, 0, 0};
while (process != NULL) {
int wait_time = current_time - process->arrival_time;
if (wait_time < 0) {
wait_time = 0;
}
process->wait_time = wait_time;
process->completion_time = process->execution_time + process->wait_time;
current_time = process->arrival_time + process->completion_time;
process = process->next_pinfo;
}
perf->total_time = current_time;
return perf;
}
struct pinfo * read_file() {
// TODO
}
void write_file(struct pinfo * process, struct perf_info * perf) {
// TODO
}
void print_perf(struct perf_info * perf) {
println("Total time: %d\n", perf->total_time);
println("Total number of context switches: %d\n", perf->total_nr_ctxt_switch);
println("Total time spent on context switching: %d\n", perf->total_time_ctxt_switch);
}
int main() {
struct pinfo * processes = read_file();
struct perf_info * perf = schedule_FCFS(processes);
write_file(processes, perf);
print_perf(perf);
return 0;
}