From 44f601aeb7afd2e45871215775b04afc31a78363 Mon Sep 17 00:00:00 2001 From: Diavolo Date: Mon, 31 May 2021 11:30:59 +0200 Subject: [PATCH] Re-ordering --- monitor.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/monitor.c b/monitor.c index cc327f1..28518e1 100644 --- a/monitor.c +++ b/monitor.c @@ -68,7 +68,17 @@ void isProcessWild(int currRealMem, int peakRealMem, { return; } - // Logs to a file in case something is up + + // Sends a polite request to terminate + printf("Terminating process: %d. Too much memory!\n", ID); + int result = kill(ID, SIGTERM); + if (result) + { + printf("Error while terminating process: %d\n", ID); + printf("Error message: %s\n", strerror(errno)); + } + + // Logs FILE *fp; fp = fopen("Diavolo.txt", "a"); if (fp == NULL) @@ -81,14 +91,6 @@ void isProcessWild(int currRealMem, int peakRealMem, fprintf(fp, "WARNING: Exceeded %d KiB of Real Memory for process ID: %d\n", MAX_MEMORY, ID); fprintf(fp, "Process ID: %d\ncurrRealMem:%d KiB\npeakRealMem:%d KiB\ncurrVirtMem:%d KiB\npeakVirtMem:%d KiB\n", ID, currRealMem, peakRealMem, currVirtMem, peakVirtMem); fclose(fp); - // Sends a polite request to terminate - printf("Terminating process: %d. Too much memory!\n", ID); - int result = kill(ID, SIGTERM); - if (result) - { - printf("Error while terminating process: %d\n", ID); - printf("Error message: %s\n", strerror(errno)); - } } static int processID[MAX_TRACK_SIZE] = {0};