Re: Fw: epoll and fork()

From: Ben
Date: Tue Mar 02 2004 - 10:39:12 EST


On Tue, 2 Mar 2004, Davide Libenzi wrote:

> >
> > Is there a defined behaviour for what happens when a process with an epoll
> > fd forks?
> >
> > I've an app that inherits an epoll fd from its parent, and then
> > unregisters some file descriptors from the epoll set. This seems to have
> > the nasty side effect of unregistering the same file descriptors from the
> > parent process as well. Surely this can't be right?
>
> epoll does register the underlying file* not the fd, so this is the
> expected behaviour. Inheriting an fd, and epoll is no exception, simply
> bumps a counter, so both parent and child epoll fd shares the same context.
> Sorry but what behaviour do you expect by unregistering an fd pushed by
> the parent from inside a child? Events work exactly the same. Since the
> context is shared, events are delivered only once.

It seems unintuitive, although having heard the arguments, I can
understand why it works this way.

I was thinking that epoll should behave like a file descriptor (i.e. a
child can close an inherited fd without affecting the parent), simply
because the only connection a process has with epoll is the file
descriptor. I suppose if you think of epoll_ctl() and epoll_wait() as
write()s and read()s on the file descriptor, then it makes sense that
these operations would affect both processes.

It still feels 'wrong' though :)


Ben
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/