When the JVM creates a log file with log rotation enabled, it creates a file with a name like this:
logfile.0.current
After it reaches a file size threshold, and rotates to a new file, it moves the file to logfile.0
and creates a new file: logfile.1.current
I have a program which reads from these logfiles and does some processing on it and then writes the content to a single file.
The code for reading from the file is something similar to this:
ssize_t numRead = read(_fd, buffer, BUF_SIZE - 1);
// I want to know how to handle the situation if file gets deleted here
char * msg = new char[numRead + 1];
strncpy(msg, buffer, numRead);
msg[numRead] = '\0';
// write the msg to a different file.
But I'm struggling to handle the situation where logfile.0.current
gets moved to logfile.0
.
- What happens to the file descriptor at that point?
- Is there any signal that I can detect at this point to handle it?