From: DervishD <raul@pleyades.net>
To: "Richard B. Johnson" <root@chaos.analogic.com>
Cc: "Sparks, Jamie" <JAMIE.SPARKS@cubic.com>,
Linux kernel <linux-kernel@vger.kernel.org>
Subject: Re: select() stress
Date: Tue, 18 Mar 2003 15:42:59 +0100 [thread overview]
Message-ID: <20030318144259.GA1438@DervishD> (raw)
In-Reply-To: <Pine.LNX.4.53.0303180758380.26753@chaos>
Hi Richard :)
Richard B. Johnson dixit:
> > > descriptors. You cannot assume that this number is the same
> > > as the currently open socket. Just use the socket-value. That's
> > > the file-descriptor.
> > Not at all. 'select()' takes a *number of file descriptors* as
> > its first argument, meaning the maximum number of file descriptors to
> > check (it checks only the first N file descriptors, being 'N' the
> > first argument). Usually that first argument is FD_SETSIZE, but the
> > result of any function returning a number is right if you know that
> > the return value is what you want.
> What I said has been misinterpreted. Select takes the highest
> number fd in the set you want to examine plus 1.
AFAIK, only if the first argument is 'FD_SETSIZE', but I'm not
sure of this point.
And yes, now I understand what you meant, and you're right. If
you put in the set file descriptor 'N', you *must* put in the first
argument at least N+1, or the file descriptor won't be checked.
Anyway, in the case of 'getdtablesize()', and assuming that it
returns the highest 'openable' file descriptor, it will always return
a number that is higher than any open file descriptor that the
process has (except if it's inherited from the parent and the child
has a lower file descriptor limit, but this involves tweaking with
getdtablesize()...), since the fd numbers start from zero.
> They are not the same and are not guaranteed to be related although
> on some target, they might.
That's what I didn't understand with getdtablesize(). In the man
page I can read that the function returns the size of the descriptor
table for the process, not the highest number for a file descriptor,
so you can't use it for 'select()', because you can have a socket
descriptor with value e.g. 40055 open and getdtablesize() will
return, for example, 1024. That is, you can open 1024 file
descriptors in your process, but the open call can return 40000 :?
This leads me to the following thinking: I thought that the code
below is a good way of closing all opened file descriptors, but if
the OS can return an arbitrary number higher than the descriptor
table size for a file descriptor, won't work:
for (i=0; i < getdtablesize(); i++) close(i);
How can this be achieved, knowing that the return value for
getdtablesize() doesn't need to be related with fd numbers (that is,
the kernel can return any arbitrary value for a file descriptor,
given that the limit for OPEN_MAX or getdtablesize() is honored)?
Interesting issue :) Thanks, Richard.
Raúl Núñez de Arenas Coronado
--
Linux Registered User 88736
http://www.pleyades.net & http://www.pleyades.net/~raulnac
next prev parent reply other threads:[~2003-03-18 14:33 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-03-17 15:28 select() stress Sparks, Jamie
2003-03-17 15:43 ` Matti Aarnio
2003-03-17 16:15 ` Richard B. Johnson
2003-03-17 18:00 ` Miquel van Smoorenburg
2003-03-17 18:24 ` Olaf Titz
2003-03-18 10:28 ` DervishD
2003-03-18 13:06 ` Richard B. Johnson
2003-03-18 14:42 ` DervishD [this message]
2003-03-18 14:46 ` DervishD
-- strict thread matches above, loose matches on Subject: below --
2003-03-18 14:49 Sparks, Jamie
2003-03-18 15:05 ` Richard B. Johnson
2003-03-18 15:05 ` Sparks, Jamie
2003-03-19 4:18 ` Chris Friesen
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=20030318144259.GA1438@DervishD \
--to=raul@pleyades.net \
--cc=JAMIE.SPARKS@cubic.com \
--cc=linux-kernel@vger.kernel.org \
--cc=root@chaos.analogic.com \
/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.