write_file. Bugg à comprendre...
This commit is contained in:
parent
4f7893b70e
commit
4c221983c0
46
simulator.c
46
simulator.c
@ -18,7 +18,7 @@ struct pinfo {
|
||||
int priority;
|
||||
|
||||
int wait_time;
|
||||
int completion_time;
|
||||
int turnaround_time;
|
||||
int remaining_time;
|
||||
enum pstate state;
|
||||
|
||||
@ -44,7 +44,7 @@ void print_pinfo(struct pinfo * info) {
|
||||
printf(" Execution time: %d\n", info->execution_time);
|
||||
printf(" Priority: %d\n", info->priority);
|
||||
printf(" Wait time: %d\n", info->wait_time);
|
||||
printf(" Completion time: %d\n", info->completion_time);
|
||||
printf(" Turnaround time: %d\n", info->turnaround_time);
|
||||
printf(" Remaining time: %d\n", info->remaining_time);
|
||||
printf(" NEXT -> %p\n", info->next_pinfo);
|
||||
printf("}>\n");
|
||||
@ -64,7 +64,7 @@ struct pinfo * create_process(int id, int arrival_time, int execution_time, int
|
||||
info->execution_time = execution_time;
|
||||
info->priority = priority;
|
||||
info->wait_time = 0;
|
||||
info->completion_time = 0;
|
||||
info->turnaround_time = 0;
|
||||
info->remaining_time = execution_time;
|
||||
info->state = WAITING;
|
||||
info->next_pinfo = NULL;
|
||||
@ -83,8 +83,8 @@ struct perf_info schedule_FCFS(struct pinfo * processes) {
|
||||
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->turnaround_time = process->execution_time + process->wait_time;
|
||||
current_time = process->arrival_time + process->turnaround_time;
|
||||
|
||||
process = process->next_pinfo;
|
||||
}
|
||||
@ -139,16 +139,32 @@ struct pinfo * read_file() {
|
||||
}
|
||||
|
||||
void write_file(struct pinfo * process, struct perf_info * perf) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
void free_processes(struct pinfo * next) {
|
||||
struct pinfo * cur;
|
||||
while (next != NULL) {
|
||||
cur = next;
|
||||
next = cur->next_pinfo;
|
||||
free(cur);
|
||||
FILE *myStream_execution = fopen("execution.csv", "w");
|
||||
FILE *myStream_performance = fopen("performance.csv", "w");
|
||||
|
||||
if (myStream_execution == NULL || myStream_performance == NULL) {
|
||||
perror("Erreur à l'ouverture des fichiers");
|
||||
return;
|
||||
}
|
||||
|
||||
while (process != NULL) {
|
||||
fprintf(myStream_execution, "%d,%d,%d\n",
|
||||
process->id,
|
||||
process->turnaround_time,
|
||||
process->wait_time);
|
||||
process = process->next_pinfo;
|
||||
}
|
||||
fclose(myStream_execution);
|
||||
|
||||
|
||||
fprintf(myStream_performance, "%d,%d,%d\n",
|
||||
perf->total_time,
|
||||
perf->total_nr_ctxt_switch,
|
||||
perf->total_time_ctxt_switch);
|
||||
|
||||
|
||||
fclose(myStream_performance);
|
||||
}
|
||||
|
||||
int main() {
|
||||
@ -156,11 +172,13 @@ int main() {
|
||||
|
||||
struct perf_info perf = schedule_FCFS(processes);
|
||||
|
||||
//write_file(processes, &perf);
|
||||
write_file(processes, &perf);
|
||||
print_processes(processes);
|
||||
print_perf(&perf);
|
||||
|
||||
free_processes(processes);
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user