Re: Repost: Bug with select?

From: Ben Greear (greearb@candelatech.com)
Date: Fri Jul 25 2003 - 19:20:13 EST


Marco Roeland wrote:
> On Thursday July 24th 2003 at 01:28 uur Eli Barzilay wrote:
>
>
>>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);
>
>
> You use non-blocking mode here.
>
>
>> while (1) {
>> FD_ZERO(&writefds);
>> FD_SET(fd, &writefds);
>> len = select(fd + 1, NULL, &writefds, NULL, NULL);
>
>
> A select with no timeout, so it will immediately return.
>
>
>> if (!FD_ISSET(fd,&writefds)) exit(0);
>
>
> This might be what Solaris does differently, by _not_ including '1' in
> the returned descriptors? Linux will say (rightly) that a following call
> will not block, which is something very different than 'will not fail'!

I thought select is supposed to tell you when you can read/write at least something without
failing. Otherwise it would be worthless when doing non-blocking IO because you can
both read and write w/out blocking at all times. If you run similar code on a tcp
socket instead of std-out, do you see the same busy spin? (To do it right, make
sure the network between source and destination is slower than the CPU can handle,
ie 10bt hub.)

-- 
Ben Greear <greearb@candelatech.com>
Candela Technologies Inc  http://www.candelatech.com

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



This archive was generated by hypermail 2b29 : Thu Jul 31 2003 - 22:00:27 EST