|
@@ -3,8 +3,28 @@
|
|
#include <signal.h>
|
|
#include <signal.h>
|
|
#include <unistd.h>
|
|
#include <unistd.h>
|
|
#include <stdlib.h>
|
|
#include <stdlib.h>
|
|
|
|
+#include <time.h>
|
|
|
|
|
|
char buffer[100];
|
|
char buffer[100];
|
|
|
|
+clock_t current_time;
|
|
|
|
+
|
|
|
|
+void elapsedTimeToString(char *output, size_t size) {
|
|
|
|
+ static clock_t start_time = 0;
|
|
|
|
+
|
|
|
|
+ if (start_time == 0) {
|
|
|
|
+ // Enregistrez le temps de démarrage lors de la première invocation
|
|
|
|
+ start_time = clock();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // Calculez le temps écoulé depuis le démarrage du programme
|
|
|
|
+ clock_t current_time = clock();
|
|
|
|
+ double elapsed_time = ((double)(current_time - start_time)) / CLOCKS_PER_SEC;
|
|
|
|
+
|
|
|
|
+ // Écrivez le temps écoulé dans la chaîne de texte
|
|
|
|
+ snprintf(output, size, "Temps écoulé : %.2f secondes", elapsed_time);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
int writeToFile(const char* text) {
|
|
int writeToFile(const char* text) {
|
|
FILE *file;
|
|
FILE *file;
|
|
|
|
|
|
@@ -32,6 +52,8 @@ int writeToFile(const char* text) {
|
|
void handle_sigterm(int signum) {
|
|
void handle_sigterm(int signum) {
|
|
printf("Received SIGTERM (%d).\n", signum);
|
|
printf("Received SIGTERM (%d).\n", signum);
|
|
snprintf(buffer,sizeof(buffer), "Received SIGTERM (%d).\n",signum);
|
|
snprintf(buffer,sizeof(buffer), "Received SIGTERM (%d).\n",signum);
|
|
|
|
+ writeToFile(buffer);
|
|
|
|
+ elapsedTimeToString(buffer, sizeof(buffer));
|
|
writeToFile(buffer);
|
|
writeToFile(buffer);
|
|
// Ajoutez ici le code de nettoyage ou de gestion du signal SIGKILL
|
|
// Ajoutez ici le code de nettoyage ou de gestion du signal SIGKILL
|
|
|
|
|
|
@@ -44,6 +66,10 @@ void handle_sigterm(int signum) {
|
|
|
|
|
|
void handle_sigint(int signum) {
|
|
void handle_sigint(int signum) {
|
|
printf("Received SIGINT (%d).\n", signum);
|
|
printf("Received SIGINT (%d).\n", signum);
|
|
|
|
+ snprintf(buffer,sizeof(buffer), "Received SIGINT (%d).\n",signum);
|
|
|
|
+ writeToFile(buffer);
|
|
|
|
+ elapsedTimeToString(buffer, sizeof(buffer));
|
|
|
|
+ writeToFile(buffer);
|
|
exit(EXIT_SUCCESS);
|
|
exit(EXIT_SUCCESS);
|
|
}
|
|
}
|
|
|
|
|