I have a program that is polling a file for changes. However, if I open another Linux console and delete the file that it is polling, while it is polling, the program will continue to poll forever. Is there a way to catch this?
struct pollfd pollFileDescriptor;
pollFileDescriptor.fd = GetFileDescriptor(...returns fd
pollFileDescriptor.events = POLLPRI | POLLERR | POLLNVAL | POLLHUP;
if (poll(&pollFileDescriptor, 1, -1) > 0)
{
...
}
I have tried all the various events, checking them against revents, as well as just putting a printf within the polling if statement just to see if it enters the code block with no luck. It seems to hang on poll