SUSv3说“常规文件应始终对TRUE进行读写”。参见http://www.opengroup.org/onlinepubs/009695399/functions/poll.html
因此,您必须在POLLPRI中使用poll | POLLERR标志。像这样:
int mfd = open("/proc/mounts", O_RDONLY, 0);
struct pollfd pfd;
int rv;
int changes = 0;
pfd.fd = mfd;
pfd.events = POLLERR | POLLPRI;
pfd.revents = 0;
while ((rv = poll(&pfd, 1, 5)) >= 0) {
if (pfd.revents & POLLERR) {
fprintf(stdout, "Mount points changed. %d.\n", changes++);
}
pfd.revents = 0;
if (changes > 10) {
exit(EXIT_FAILURE);
}
}