[ale] Select()

Bob Toxen transam at VerySecureLinux.com
Mon Aug 16 19:14:26 EDT 2010


If your open file descriptors are:

  0,1,2,7

nfds is max(0,1,2,7)+1 or 7+1 or 8.

The select() code then does (8-1) to get 7 and that's the bitmask it
uses to watch for events.

It's an efficiency thing to tell select() to test a change of status on
the first 7 file descriptors and then see if any of those are in your
three sets to watch.

On Mon, Aug 16, 2010 at 03:23:31PM -0400, Calvin Harrigan wrote:
> I'm taking a long overdue plunge back into linux C programming.  While 
> reading the man page for select(), I came across a line that has me a 
> bit confused.
> 
> http://linux.die.net/man/2/select
> 
> "nfds is the highest-numbered file descriptor in any of the three sets, 
> plus 1."
> 
> What exactly are they referring to? What is highest-numbered file 
> descriptor?  Are they referring to integer value stored in the file 
> descriptor? Perhaps it's the number of file descriptors added to the 
> set?  It's not very clear to me.  Any insight would be greatly appreciated.
> 
> Thanks


You're welcome.

Bob Toxen
bob at verysecurelinux.com               [Please use for email to me]
http://www.verysecurelinux.com        [Network&Linux security consulting]
http://www.realworldlinuxsecurity.com [My book:"Real World Linux Security 2/e"]
Quality spam and virus filters.
Quality Linux & UNIX security and SysAdmin & software consulting since 1990.

"One disk to rule them all, One disk to find them. One disk to bring
them all and in the darkness grind them. In the Land of Redmond where
the shadows lie...and the Eye is everwatching"
-- The Silicon Valley Tarot Henrique Holschuh with ... by Bob


More information about the Ale mailing list