mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Richard B. Johnson" <root@chaos.analogic.com>
To: Mihai RUSU <dizzy@roedu.net>
Cc: Ben <linux-kernel-junk-email@slimyhorror.com>,
	linux-kernel@vger.kernel.org
Subject: Re: epoll and fork()
Date: Tue, 2 Mar 2004 08:20:42 -0500 (EST)	[thread overview]
Message-ID: <Pine.LNX.4.53.0403020809140.15850@chaos> (raw)
In-Reply-To: <Pine.LNX.4.58L0.0403021454070.20334@ahriman.bucharest.roedu.net>

On Tue, 2 Mar 2004, Mihai RUSU wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On Tue, 2 Mar 2004, Ben 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?
> >
> > This is on 2.6.2.
>
> Currect me if Im wrong but...
>
> After a fork() arent all the parent's fds shared with the children ? This
> means that both processes can access the same fds right ? So the epoll fd
> (beeing just another fd as any other) is too shared between parent and
> child ? Which would mean both parent and child will "control" the same
> epoll kernel struct when doing epoll_ctl on it ?
>
> > Ben
>

The child's fds are separate, though. The parent can close
its fds without affecting the child's and the child can close
its fds without affecting the parent. Given that, suppose that
the fds related to a terminal. If the child changed the terminal
attributes, this would certainly affect the parent's terminal
since they are the same. It is possible that epoll handles
these attributes the same way and it is likely that such
behavior is "undefined". A fix may be for the child to dup()
the fds and set up its own epoll_ctl using them. If the epoll
relates to a controlling terminal, it is possible that if the
child executes setsid(), becomes its own session leader, then
the epoll  problem will go away because the parent's controlling
terminal and the child's controlling terminal become divorced.

Cheers,
Dick Johnson
Penguin : Linux version 2.4.24 on an i686 machine (797.90 BogoMips).
            Note 96.31% of all statistics are fiction.



  reply	other threads:[~2004-03-02 13:19 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-03-02 12:31 Ben
2004-03-02 12:59 ` Mihai RUSU
2004-03-02 13:20   ` Richard B. Johnson [this message]
2004-03-02 14:02     ` Mihai RUSU
2004-03-02 15:42 ` Mark Mielke

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.4.53.0403020809140.15850@chaos \
    --to=root@chaos.analogic.com \
    --cc=dizzy@roedu.net \
    --cc=linux-kernel-junk-email@slimyhorror.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®