I have a process opening a file in append mode. In this case it is a log file. Sample code:
int main(int argc, char **argv) {
FILE *f;
f = fopen("log.txt", "a");
fprintf(f, "log entry line");
fclose(f);
}
Two questions:
- If I have multiple processes appending to the same file, will each log line appear distinctly or can they be interlaced as the processes context switch?
- Will this write block if lots of processes require access to the file, therefore causing concurrency problems?
I am considering either doing this in its simplest incarnation or using zeromq to pump log entries over pipes to a log collector.
I did consider syslog but I don't really want any platform dependencies on the software.
The default platform is Linux for this btw.