For the level-triggered case, it is pretty straightforward:
- Yes, you can combine the answers to Q2 and Q3 from the Q&A part in epoll(7) manpage:
A2: If the same file descriptor is added to two epoll instances, events are reported to both of them.
A3: If an epoll file descriptor has events waiting, then it will indicate as being readable.
- No, since clearing the event is only relevant for edge-triggered epoll.
For the edge-triggered case, we would expect the answer to 1 to stay the same, since regardless of nesting, if the same FD is added with EPOLLET
to two epoll instances they will both report every event once.
I don't know what the answer to the second question SHOULD be, but it doesn't matter. There is a bug when adding epoll FDs in edge-triggerd mode, they just always behave like level-triggered, FD2 and FD3 will continue to show that FD1 is readable as long as it has pending events.
You can see this thread about an attempt to fix it which I don't think made to mainland yet:
fs/epoll: fix the edge-triggered mode for nested epoll
Which links to this GitHub repo which tests a lot of different scenarios, that you might find interesting.