I'm wondering whether there is a way to find out what descriptors (and the expected events) are registered for a particular epoll instance using gdb or some other inspection tool?
It's fairly easy to find it out when poll or select is used since all this information is freely available in the memory visible to a running process and can be explored in a debugger. However, epoll is somewhat different since it keeps all this data in kernel space. I realize, I can instrument my code with traces to know at every particular moment what events are expected by the epoll instance, but having some other way would be very handy for me.
Thanks
From the Linux Programmer's manual page for 'epoll_ctl' under 'ERRORS'
EEXIST op was EPOLL_CTL_ADD, and the supplied file descriptor fd is already registered with this epoll instance.
If you use EPOLL_CTL_ADD and get a return value of -1 and errno is EEXIST, then the file descriptor was already registered. Obviously, this has the side effect of registering the file descriptor, so you may need to follow up with a call using EPOLL_CTL_DEL to remove any you did not intend to be in the epoll.
Generally, I suggest avoiding the use of error cases as regular flow of a program. But it sounds like you are just doing this for debugging, so I don't really consider it a problem. Debuggers are all really just hacks anyways.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With