From 4c221983c01e69c9b4ef551bf213ef918e7dc450 Mon Sep 17 00:00:00 2001 From: "florian.sauzeat" Date: Tue, 8 Oct 2024 16:44:55 +0200 Subject: [PATCH 1/4] =?UTF-8?q?write=5Ffile.=20Bugg=20=C3=A0=20comprendre.?= =?UTF-8?q?..?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- simulator.c | 46 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/simulator.c b/simulator.c index e117924..7a0c68d 100644 --- a/simulator.c +++ b/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 -} + + FILE *myStream_execution = fopen("execution.csv", "w"); + FILE *myStream_performance = fopen("performance.csv", "w"); -void free_processes(struct pinfo * next) { - struct pinfo * cur; - while (next != NULL) { - cur = next; - next = cur->next_pinfo; - free(cur); + 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; } \ No newline at end of file From fb90cbf14a8463737cbe95edc93d5dce106b5480 Mon Sep 17 00:00:00 2001 From: "florian.sauzeat" Date: Mon, 14 Oct 2024 17:20:29 +0200 Subject: [PATCH 2/4] Try --- execution.csv | 10 +++++ performance.csv | 1 + simulator.c | 117 ++++++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 119 insertions(+), 9 deletions(-) create mode 100644 execution.csv create mode 100644 performance.csv diff --git a/execution.csv b/execution.csv new file mode 100644 index 0000000..0b49b10 --- /dev/null +++ b/execution.csv @@ -0,0 +1,10 @@ +1,10,0 +2,40,0 +3,50,30 +4,30,20 +5,40,10 +6,50,30 +7,90,40 +8,90,60 +9,50,40 +10,90,30 diff --git a/performance.csv b/performance.csv new file mode 100644 index 0000000..12ff7e7 --- /dev/null +++ b/performance.csv @@ -0,0 +1 @@ +290,0,0 diff --git a/simulator.c b/simulator.c index 7a0c68d..6bc479e 100644 --- a/simulator.c +++ b/simulator.c @@ -138,10 +138,24 @@ struct pinfo * read_file() { return first; } + + + +void free_processes(struct pinfo * next) { + struct pinfo * cur; + while (next != NULL) { + cur = next; + next = cur->next_pinfo; + free(cur); + } +} + + void write_file(struct pinfo * process, struct perf_info * perf) { - FILE *myStream_execution = fopen("execution.csv", "w"); - FILE *myStream_performance = fopen("performance.csv", "w"); + FILE *myStream_execution = fopen("execution2.csv", "w"); + FILE *myStream_performance = fopen("performance2.csv", "w"); + if (myStream_execution == NULL || myStream_performance == NULL) { perror("Erreur à l'ouverture des fichiers"); @@ -149,32 +163,117 @@ void write_file(struct pinfo * process, struct perf_info * perf) { } while (process != NULL) { - fprintf(myStream_execution, "%d,%d,%d\n", + fprintf(myStream_execution, "%d,%d,%d,%d\n", // Ajout de la colonne des préemptions process->id, process->turnaround_time, - process->wait_time); + process->wait_time, + process->execution_time - process->remaining_time); // Nombre de préemptions 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); } +struct perf_info schedule_RR(struct pinfo * processes) { + int current_time = 0; // Temps actuel + int context_switches = 0; // Nombre de changements de contexte + struct perf_info perf = {0, 0, 0}; + + struct pinfo * queue = processes; // File d'attente de processus + struct pinfo * temp; // Variable temporaire pour itérer + + while (1) { + int all_done = 1; // Vérifier si tous les processus sont terminés + + // Itérer sur les processus dans la queue + temp = queue; + while (temp != NULL) { + // Vérifiez si le processus a encore du temps restant + if (temp->remaining_time > 0) { + all_done = 0; // Il y a au moins un processus qui n'est pas terminé + + // Si le temps actuel est inférieur au temps d'arrivée + if (current_time < temp->arrival_time) { + current_time = temp->arrival_time; // Mettez à jour le temps + } + + // Exécutez le processus pendant le quantum + if (temp->remaining_time > RR_QUANTUM) { + current_time += RR_QUANTUM; // Ajoute le quantum au temps + temp->remaining_time -= RR_QUANTUM; // Diminue le temps restant + context_switches++; // Compter le changement de contexte + } else { + // Le processus se termine ici + current_time += temp->remaining_time; // Ajoutez le temps restant à current_time + temp->turnaround_time = current_time - temp->arrival_time; // Calculer le TAT + temp->wait_time += (temp->turnaround_time - temp->execution_time); // Calculer le WT + temp->remaining_time = 0; // Le processus est terminé + temp->state = FINISHED; // Marquez comme terminé + } + } + temp = temp->next_pinfo; // Passer au processus suivant + } + + // Réinitialiser la file d'attente + temp = processes; // Revenir au début de la liste + struct pinfo * last = NULL; // Pour maintenir la fin de la queue + + // Créer une nouvelle file d'attente + while (temp != NULL) { + // Ne pas ajouter les processus terminés à la nouvelle queue + if (temp->remaining_time > 0) { + if (last == NULL) { + queue = temp; // Premier processus dans la nouvelle queue + } else { + last->next_pinfo = temp; // Ajouter à la fin + } + last = temp; // Mettre à jour le dernier élément de la queue + } + temp = temp->next_pinfo; // Passer au processus suivant + } + if (last != NULL) { + last->next_pinfo = NULL; // Terminer la liste + } + + // Si tous les processus sont terminés, sortez de la boucle + if (all_done) { + break; + } + } + + // Mise à jour des statistiques de performance + perf.total_time = current_time; // Total du temps écoulé + perf.total_nr_ctxt_switch = context_switches; // Total des changements de contexte + perf.total_time_ctxt_switch = context_switches * CNTXT_SWITCH; // Temps total pour les changements de contexte + + return perf; // Retournez les performances +} + + + + + + + + + + int main() { struct pinfo * processes = read_file(); - struct perf_info perf = schedule_FCFS(processes); + //struct perf_info perf = schedule_FCFS(processes); + + struct perf_info perf = schedule_RR(processes); write_file(processes, &perf); - print_processes(processes); - print_perf(&perf); + //print_processes(processes); + //print_perf(&perf); free_processes(processes); From dfab397122f8e9c476cebcff6003276b39612322 Mon Sep 17 00:00:00 2001 From: "florian.sauzeat" Date: Mon, 14 Oct 2024 21:29:04 +0200 Subject: [PATCH 3/4] =?UTF-8?q?Th=C3=A9oriquement=20RR=20bon,=20mais=20le?= =?UTF-8?q?=20temps=20de=20compilation=20est=20tr=C3=A8s=20long?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- execution.csv | 20 +++---- simulator.c | 148 +++++++++++++++++++++++++++----------------------- 2 files changed, 91 insertions(+), 77 deletions(-) diff --git a/execution.csv b/execution.csv index 0b49b10..2bc9a35 100644 --- a/execution.csv +++ b/execution.csv @@ -1,10 +1,10 @@ -1,10,0 -2,40,0 -3,50,30 -4,30,20 -5,40,10 -6,50,30 -7,90,40 -8,90,60 -9,50,40 -10,90,30 +1,10,0,0 +2,40,0,0 +3,50,30,0 +4,30,20,0 +5,40,10,0 +6,50,30,0 +7,90,40,0 +8,90,60,0 +9,50,40,0 +10,90,30,0 diff --git a/simulator.c b/simulator.c index 6bc479e..2e98f3e 100644 --- a/simulator.c +++ b/simulator.c @@ -16,6 +16,7 @@ struct pinfo { int arrival_time; int execution_time; int priority; + int nb_time_pre_empted; int wait_time; int turnaround_time; @@ -153,8 +154,8 @@ void free_processes(struct pinfo * next) { void write_file(struct pinfo * process, struct perf_info * perf) { - FILE *myStream_execution = fopen("execution2.csv", "w"); - FILE *myStream_performance = fopen("performance2.csv", "w"); + FILE *myStream_execution = fopen("executionRR.csv", "w"); + FILE *myStream_performance = fopen("performanceRR.csv", "w"); if (myStream_execution == NULL || myStream_performance == NULL) { @@ -163,96 +164,109 @@ void write_file(struct pinfo * process, struct perf_info * perf) { } while (process != NULL) { - fprintf(myStream_execution, "%d,%d,%d,%d\n", // Ajout de la colonne des préemptions + fprintf(myStream_execution, "%d,%d,%d,%d\n", process->id, process->turnaround_time, process->wait_time, - process->execution_time - process->remaining_time); // Nombre de préemptions + process->nb_time_pre_empted); 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); } -struct perf_info schedule_RR(struct pinfo * processes) { - int current_time = 0; // Temps actuel - int context_switches = 0; // Nombre de changements de contexte +struct pinfo *enqueue(struct pinfo *queue, struct pinfo *process) { + if (queue == NULL) { + return process; + } + struct pinfo *temp = queue; + while (temp->next_pinfo != NULL) { + temp = temp->next_pinfo; + } + temp->next_pinfo = process; + return queue; +} + +struct pinfo *dequeue(struct pinfo **queue) { + if (*queue == NULL) { + return NULL; + } + struct pinfo *process = *queue; + *queue = (*queue)->next_pinfo; + process->next_pinfo = NULL; + return process; +} + + + +struct perf_info schedule_RR(struct pinfo *processes) { struct perf_info perf = {0, 0, 0}; + int current_time = 0; + struct pinfo *queue = NULL; + struct pinfo *current_process = NULL; + int remaining_quantum = RR_QUANTUM; - struct pinfo * queue = processes; // File d'attente de processus - struct pinfo * temp; // Variable temporaire pour itérer + while (processes != NULL || queue != NULL || current_process != NULL) { + // Ajouter les nouveaux processus arrivés à la file d'attente + while (processes != NULL && processes->arrival_time <= current_time) { + processes->state = READY; + queue = enqueue(queue, processes); + printf("Processus %d ajouté à la file d'attente à l'heure %d\n", processes->id, current_time); + processes = processes->next_pinfo; + } - while (1) { - int all_done = 1; // Vérifier si tous les processus sont terminés + // Si aucun processus en cours, prendre le suivant dans la file d'attente + if (current_process == NULL && queue != NULL) { + current_process = dequeue(&queue); + current_process->nb_time_pre_empted++; + remaining_quantum = RR_QUANTUM; // Réinitialiser le quantum + printf("Processus %d pris de la file d'attente pour exécution à l'heure %d\n", current_process->id, current_time); + } - // Itérer sur les processus dans la queue - temp = queue; - while (temp != NULL) { - // Vérifiez si le processus a encore du temps restant - if (temp->remaining_time > 0) { - all_done = 0; // Il y a au moins un processus qui n'est pas terminé + // Exécuter le processus courant + if (current_process != NULL) { + current_process->remaining_time--; + current_process->turnaround_time++; + remaining_quantum--; + printf("Processus %d exécuté à l'heure %d, temps restant: %d, quantum restant: %d\n", current_process->id, current_time, current_process->remaining_time, remaining_quantum); + current_time++; - // Si le temps actuel est inférieur au temps d'arrivée - if (current_time < temp->arrival_time) { - current_time = temp->arrival_time; // Mettez à jour le temps - } - - // Exécutez le processus pendant le quantum - if (temp->remaining_time > RR_QUANTUM) { - current_time += RR_QUANTUM; // Ajoute le quantum au temps - temp->remaining_time -= RR_QUANTUM; // Diminue le temps restant - context_switches++; // Compter le changement de contexte - } else { - // Le processus se termine ici - current_time += temp->remaining_time; // Ajoutez le temps restant à current_time - temp->turnaround_time = current_time - temp->arrival_time; // Calculer le TAT - temp->wait_time += (temp->turnaround_time - temp->execution_time); // Calculer le WT - temp->remaining_time = 0; // Le processus est terminé - temp->state = FINISHED; // Marquez comme terminé - } + // Vérifier si le processus est terminé + if (current_process->remaining_time == 0) { + current_process->state = FINISHED; + printf("Processus %d terminé à l'heure %d\n", current_process->id, current_time); + current_process = NULL; + } else if (remaining_quantum == 0) { + // Si le quantum RR est atteint, remettre le processus en file d'attente + current_process->state = WAITING; + queue = enqueue(queue, current_process); + printf("Processus %d préempté et remis en file d'attente à l'heure %d\n", current_process->id, current_time); + current_process = NULL; } - temp = temp->next_pinfo; // Passer au processus suivant + } else { + // Si aucun processus à exécuter, avancer le temps + printf("Aucun processus à exécuter à l'heure %d, avancer le temps\n", current_time); + current_time++; } - // Réinitialiser la file d'attente - temp = processes; // Revenir au début de la liste - struct pinfo * last = NULL; // Pour maintenir la fin de la queue - - // Créer une nouvelle file d'attente - while (temp != NULL) { - // Ne pas ajouter les processus terminés à la nouvelle queue - if (temp->remaining_time > 0) { - if (last == NULL) { - queue = temp; // Premier processus dans la nouvelle queue - } else { - last->next_pinfo = temp; // Ajouter à la fin - } - last = temp; // Mettre à jour le dernier élément de la queue - } - temp = temp->next_pinfo; // Passer au processus suivant - } - if (last != NULL) { - last->next_pinfo = NULL; // Terminer la liste - } - - // Si tous les processus sont terminés, sortez de la boucle - if (all_done) { - break; - } + // Mise à jour des performances + perf.total_time = current_time; + perf.total_nr_ctxt_switch++; + perf.total_time_ctxt_switch += CNTXT_SWITCH; } - // Mise à jour des statistiques de performance - perf.total_time = current_time; // Total du temps écoulé - perf.total_nr_ctxt_switch = context_switches; // Total des changements de contexte - perf.total_time_ctxt_switch = context_switches * CNTXT_SWITCH; // Temps total pour les changements de contexte - - return perf; // Retournez les performances + printf("Planification RR terminée\n"); + return perf; } From 5509743101146b5edb250159c7cdf6be59f5ee04 Mon Sep 17 00:00:00 2001 From: "florian.sauzeat" Date: Tue, 15 Oct 2024 10:27:35 +0200 Subject: [PATCH 4/4] RR fait --- execution.csv => executionFCFS.csv | 0 executionRR.csv | 10 ++ performance.csv => performanceFCFS.csv | 0 performanceRR.csv | 1 + results.csv | 11 ++ simulator.c | 239 +++++++++++-------------- tempCodeRunnerFile | Bin 0 -> 16824 bytes 7 files changed, 122 insertions(+), 139 deletions(-) rename execution.csv => executionFCFS.csv (100%) create mode 100644 executionRR.csv rename performance.csv => performanceFCFS.csv (100%) create mode 100644 performanceRR.csv create mode 100644 results.csv create mode 100755 tempCodeRunnerFile diff --git a/execution.csv b/executionFCFS.csv similarity index 100% rename from execution.csv rename to executionFCFS.csv diff --git a/executionRR.csv b/executionRR.csv new file mode 100644 index 0000000..7c4c0c1 --- /dev/null +++ b/executionRR.csv @@ -0,0 +1,10 @@ +1,10,0,4 +2,84,44,19 +3,42,24,9 +4,22,14,4 +5,94,66,14 +6,66,48,9 +7,148,100,24 +8,98,70,14 +9,30,22,4 +10,90,32,29 diff --git a/performance.csv b/performanceFCFS.csv similarity index 100% rename from performance.csv rename to performanceFCFS.csv diff --git a/performanceRR.csv b/performanceRR.csv new file mode 100644 index 0000000..fc78dc5 --- /dev/null +++ b/performanceRR.csv @@ -0,0 +1 @@ +290,130,0 diff --git a/results.csv b/results.csv new file mode 100644 index 0000000..1f04bcb --- /dev/null +++ b/results.csv @@ -0,0 +1,11 @@ +PID,Arrival Time,Execution Time,Wait Time,Turnaround Time,Remaining Time +1,0,10,6,14,0 +2,20,40,545,129,0 +3,30,20,123,54,0 +4,60,10,42,33,0 +5,80,30,709,140,0 +6,90,20,295,90,0 +7,100,50,2016,196,0 +8,130,30,739,131,0 +9,180,10,60,46,0 +10,200,60,1694,143,0 diff --git a/simulator.c b/simulator.c index 2e98f3e..b999e86 100644 --- a/simulator.c +++ b/simulator.c @@ -4,6 +4,7 @@ #define RR_QUANTUM 2 #define CNTXT_SWITCH 1 +#define MAX_PROCESSES 10 enum pstate { WAITING, @@ -16,11 +17,11 @@ struct pinfo { int arrival_time; int execution_time; int priority; - int nb_time_pre_empted; int wait_time; int turnaround_time; int remaining_time; + int nb_time_pre_empted; // Ajouté pour compter les préemptions enum pstate state; struct pinfo * next_pinfo; @@ -67,11 +68,13 @@ struct pinfo * create_process(int id, int arrival_time, int execution_time, int info->wait_time = 0; info->turnaround_time = 0; info->remaining_time = execution_time; + info->nb_time_pre_empted = 0; // Initialiser le nombre de préemptions info->state = WAITING; info->next_pinfo = NULL; return info; } +// Méthode de planification FCFS struct perf_info schedule_FCFS(struct pinfo * processes) { int current_time = 0; struct pinfo * process = processes; @@ -94,6 +97,97 @@ struct perf_info schedule_FCFS(struct pinfo * processes) { return perf; } +struct perf_info schedule_RR(struct pinfo *processes) { // Déclaration de la fonction schedule_RR qui prend un pointeur vers une liste de processus + struct perf_info perf = {0, 0, 0}; // Initialisation de la structure de performance avec des valeurs à zéro + int current_time = 0; // Variable pour suivre le temps actuel + int finished_processes = 0; // Compteur pour le nombre de processus terminés + + while (finished_processes < MAX_PROCESSES) { // Boucle principale jusqu'à ce que tous les processus soient terminés + int process_found = 0; // Indicateur pour savoir si un processus prêt a été trouvé + struct pinfo *current_process = processes; // Pointeur pour parcourir la liste des processus + + while (current_process != NULL) { // Boucle pour parcourir tous les processus + // Vérifiez si le processus est prêt à s'exécuter + if (current_process->state != FINISHED && current_process->arrival_time <= current_time) { // Vérifie si le processus n'est pas fini et est arrivé + process_found = 1; // Un processus prêt à s'exécuter a été trouvé + + int time_slice = (current_process->remaining_time < RR_QUANTUM) ? current_process->remaining_time : RR_QUANTUM; // Calcule la tranche de temps à exécuter + + // Simuler l'exécution + current_time += time_slice; // Incrémente le temps actuel par la tranche de temps + current_process->remaining_time -= time_slice; // Diminue le temps restant du processus + + // Calculer les temps d'attente pour les autres processus + struct pinfo *other_process = processes; // Pointeur pour parcourir à nouveau la liste des processus + while (other_process != NULL) { // Boucle pour parcourir tous les autres processus + if (other_process->state != FINISHED && other_process != current_process && other_process->arrival_time <= current_time) { // Vérifie si l'autre processus est prêt + other_process->wait_time += time_slice; // Augmente le temps d'attente des autres processus + } + other_process = other_process->next_pinfo; // Passe au processus suivant + } + + // Gérer les statistiques de préemption + if (current_process->remaining_time == 0) { // Vérifie si le processus est terminé + current_process->state = FINISHED; // Met à jour l'état du processus à fini + finished_processes++; // Incrémente le compteur de processus terminés + current_process->turnaround_time = current_time - current_process->arrival_time; // Calcule le temps de turnaround + } else { + // Incrémenter le nombre de préemptions + current_process->nb_time_pre_empted++; // Incrémente le compteur de préemptions pour le processus actuel + perf.total_nr_ctxt_switch++; // Incrémente le nombre total de commutations de contexte + } + + // Débogage : Afficher les informations du processus + printf("Processus %d: remaining_time=%d, nb_time_pre_empted=%d\n", // Affiche les informations de débogage pour le processus actuel + current_process->id, current_process->remaining_time, current_process->nb_time_pre_empted); + } + + current_process = current_process->next_pinfo; // Passe au processus suivant dans la liste + } + + if (!process_found) { // Vérifie si aucun processus prêt n'a été trouvé + // Aucun processus prêt, avancer le temps + current_time++; // Incrémente le temps actuel si aucun processus n'est prêt + } + } + + perf.total_time = current_time; // Enregistre le temps total écoulé dans la structure de performance + return perf; // Renvoie la structure de performance +} + + +void write_file(struct pinfo * process, struct perf_info * perf) { + FILE *myStream_execution = fopen("executionRR.csv", "w"); + FILE *myStream_performance = fopen("performanceRR.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,%d\n", + process->id, + process->turnaround_time, + process->wait_time, + process->nb_time_pre_empted); + 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); +} + + + + + + struct pinfo * read_file() { FILE * file = fopen("tasks.csv", "r"); @@ -121,12 +215,12 @@ struct pinfo * read_file() { atoi(prio_str) ); - // If linked list not initialized + // Si la liste n'est pas initialisée if (first == NULL) { first = process; } - // If there is an element in list + // Si un élément est déjà dans la liste if (last != NULL) { last->next_pinfo = process; } @@ -139,9 +233,6 @@ struct pinfo * read_file() { return first; } - - - void free_processes(struct pinfo * next) { struct pinfo * cur; while (next != NULL) { @@ -152,146 +243,16 @@ void free_processes(struct pinfo * next) { } -void write_file(struct pinfo * process, struct perf_info * perf) { - - FILE *myStream_execution = fopen("executionRR.csv", "w"); - FILE *myStream_performance = fopen("performanceRR.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,%d\n", - process->id, - process->turnaround_time, - process->wait_time, - process->nb_time_pre_empted); - 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); -} - -struct pinfo *enqueue(struct pinfo *queue, struct pinfo *process) { - if (queue == NULL) { - return process; - } - struct pinfo *temp = queue; - while (temp->next_pinfo != NULL) { - temp = temp->next_pinfo; - } - temp->next_pinfo = process; - return queue; -} - -struct pinfo *dequeue(struct pinfo **queue) { - if (*queue == NULL) { - return NULL; - } - struct pinfo *process = *queue; - *queue = (*queue)->next_pinfo; - process->next_pinfo = NULL; - return process; -} - - - -struct perf_info schedule_RR(struct pinfo *processes) { - struct perf_info perf = {0, 0, 0}; - int current_time = 0; - struct pinfo *queue = NULL; - struct pinfo *current_process = NULL; - int remaining_quantum = RR_QUANTUM; - - while (processes != NULL || queue != NULL || current_process != NULL) { - // Ajouter les nouveaux processus arrivés à la file d'attente - while (processes != NULL && processes->arrival_time <= current_time) { - processes->state = READY; - queue = enqueue(queue, processes); - printf("Processus %d ajouté à la file d'attente à l'heure %d\n", processes->id, current_time); - processes = processes->next_pinfo; - } - - // Si aucun processus en cours, prendre le suivant dans la file d'attente - if (current_process == NULL && queue != NULL) { - current_process = dequeue(&queue); - current_process->nb_time_pre_empted++; - remaining_quantum = RR_QUANTUM; // Réinitialiser le quantum - printf("Processus %d pris de la file d'attente pour exécution à l'heure %d\n", current_process->id, current_time); - } - - // Exécuter le processus courant - if (current_process != NULL) { - current_process->remaining_time--; - current_process->turnaround_time++; - remaining_quantum--; - printf("Processus %d exécuté à l'heure %d, temps restant: %d, quantum restant: %d\n", current_process->id, current_time, current_process->remaining_time, remaining_quantum); - current_time++; - - // Vérifier si le processus est terminé - if (current_process->remaining_time == 0) { - current_process->state = FINISHED; - printf("Processus %d terminé à l'heure %d\n", current_process->id, current_time); - current_process = NULL; - } else if (remaining_quantum == 0) { - // Si le quantum RR est atteint, remettre le processus en file d'attente - current_process->state = WAITING; - queue = enqueue(queue, current_process); - printf("Processus %d préempté et remis en file d'attente à l'heure %d\n", current_process->id, current_time); - current_process = NULL; - } - } else { - // Si aucun processus à exécuter, avancer le temps - printf("Aucun processus à exécuter à l'heure %d, avancer le temps\n", current_time); - current_time++; - } - - // Mise à jour des performances - perf.total_time = current_time; - perf.total_nr_ctxt_switch++; - perf.total_time_ctxt_switch += CNTXT_SWITCH; - } - - printf("Planification RR terminée\n"); - return perf; -} - - - - - - - - - int main() { struct pinfo * processes = read_file(); - //struct perf_info perf = schedule_FCFS(processes); - - struct perf_info perf = schedule_RR(processes); + //struct perf_info perf = schedule_FCFS(processes); // Remise en place de FCFS + struct perf_info perf = schedule_RR(processes); write_file(processes, &perf); - //print_processes(processes); - //print_perf(&perf); free_processes(processes); - - return 0; -} \ No newline at end of file +} diff --git a/tempCodeRunnerFile b/tempCodeRunnerFile new file mode 100755 index 0000000000000000000000000000000000000000..58ee3b3341c474e284056edcb48b3087c01befd6 GIT binary patch literal 16824 zcmeHOdvH|Oc|UppGT|Yxh{eP9tz#Sr)`EB$yT)FD7FHR+ijXF@YxlC!UZD-EU3vGe z5w4ZsDllvo)pFZOm`>7Brs;$x{zIK{8|)#qY#gL`T8|iaTxCj91w*_lvMb9tRUGW? z?>pywm%F#xv`za@XZFC=cfQ~EIOlxlvFAR{R|0!>m6ntUPG#Z&LEO+1h4{5#=3bov z@r!L@A^zSjZWD9CmrG2^{fa=U(pYIet!2VE^Wtj ziYkP}l;cU&plh3sr3VRM|Kiyn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