#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int LogCreated = 0;
void Log(charchar *message) {
FILEFILE *file;
if (LogCreated == 0) {
file = fopen("LOGFILE.log", "w"); //TO rewrite or create the log at init
LogCreated = 1;
} else {
file = fopen("LOGFILE.log", "a"); //to append to the log after init
}
if (file == NULL) {
if (LogCreated == 1) {
LogCreated = 0;
}
} else {
fputs(message, file);
fflush(file);
fclose(file); //close and open the file at each call
}
}
int main(int argc, charchar *argv[])
{
printf("PID OF MAIN %ld\n", (long)getpid());
fflush(stdout);
//INIT LOG
Log("Log INIT\n");
return 0;
}