All of lore.kernel.org
 help / color / mirror / Atom feed
From: Philippe Troin <phil@fifi.org>
To: Eli Barzilay <eli@barzilay.org>
Cc: linux-kernel@vger.kernel.org
Subject: Re: Repost: Bug with select?
Date: 25 Jul 2003 17:35:17 -0700	[thread overview]
Message-ID: <877k66qg56.fsf@ceramic.fifi.org> (raw)
In-Reply-To: <16159.28266.868297.372200@mojave.cs.cornell.edu>

Eli Barzilay <eli@barzilay.org> writes:

> [This is a second post, since I didn't get any replies the first time.
> It looks more like a bug now, which sounds strange for something that
> common...]
> 
> When I run the following program, and block the terminal's output
> (C-s), the `select' doesn't seem to have any effect, resulting in a
> 100% cpu usage (this is on a RH8, with 2.4.18).  I wouldn't be
> surprised if I'm doing something stupid, but it does seem to work fine
> on Solaris.
> 
> Is there anything wrong with this, or is this some bug?
> 
> ======================================================================
> #include <unistd.h>
> #include <fcntl.h>
> int main() {
>   int flags, fd, len; fd_set writefds;
>   fd = 1;
>   flags = fcntl(fd, F_GETFL, 0);
>   fcntl(fd, F_SETFL, flags | O_NONBLOCK);
>   while (1) {
>     FD_ZERO(&writefds);
>     FD_SET(fd, &writefds);
>     len = select(fd + 1, NULL, &writefds, NULL, NULL);
>     if (!FD_ISSET(fd,&writefds)) exit(0);
>     len = write(fd, "hi\n", 3);
>   }
>   fcntl(fd, F_SETFL, flags);
> }
> ======================================================================

Looks like a bug to me.
Strace says:

select(2, NULL, [1], NULL, NULL)        = 1 (out [1])
write(1, "hi\n", 3)                     = -1 EAGAIN (Resource temporarily unavailable)

forever.

Then select() should not return fd 1 as writable, at least not
reapeatedly.

Phil.

  parent reply	other threads:[~2003-07-26  0:20 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-06-18  8:49 Problem with select? Eli Barzilay
2003-07-24  5:28 ` Repost: Bug " Eli Barzilay
2003-07-25 13:41   ` Marco Roeland
2003-07-26  0:20     ` Ben Greear
2003-07-26  9:05       ` Marco Roeland
2003-07-26  0:35   ` Philippe Troin [this message]
2003-07-26 14:29     ` Eli Barzilay
2003-07-26 14:25   ` Eli Barzilay
2003-07-26 15:37     ` Marco Roeland
2003-07-27 19:29 Manfred Spraul

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=877k66qg56.fsf@ceramic.fifi.org \
    --to=phil@fifi.org \
    --cc=eli@barzilay.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.