Re-ordering

This commit is contained in:
2021-05-31 11:30:59 +02:00
parent b815c21dee
commit 44f601aeb7

View File

@ -68,7 +68,17 @@ void isProcessWild(int currRealMem, int peakRealMem,
{ {
return; 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; FILE *fp;
fp = fopen("Diavolo.txt", "a"); fp = fopen("Diavolo.txt", "a");
if (fp == NULL) 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, "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); 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); 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}; static int processID[MAX_TRACK_SIZE] = {0};