Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
They report different things in the return value. 'select' tells you the total number of 'ready' file descriptors - it doesn't tell you if any are for read, write, etc. - you need to check your FD sets for that. 'poll' will say something is ready to be read, write will not block, etc. 'poll' is a bit like calling 'select' with a write_FDS and read_FDS where both the read and write FDS are the same.
The basic difference is that select()'s fd_set is a bit mask and
therefore has some fixed size. It would be possible for the kernel to
not limit this size when the kernel is compiled, allowing the
application to define FD_SETSIZE to whatever it wants (as the comments
in the system header imply today) but it takes more work. 4.4BSD's
kernel and the Solaris library function both have this limit. But I
see that BSD/OS 2.1 has now been coded to avoid this limit, so it's
doable, just a small matter of programming. :-) Someone should file a
Solaris bug report on this, and see if it ever gets fixed.
With poll(), however, the user must allocate an array of pollfd
structures, and pass the number of entries in this array, so there's
no fundamental limit. As Casper notes, fewer systems have poll() than
select, so the latter is more portable. Also, with original
implementations (SVR3) you could not set the descriptor to -1 to tell
the kernel to ignore an entry in the pollfd structure, which made it
hard to remove entries from the array; SVR4 gets around this.
Personally, I always use select() and rarely poll(), because I port my
code to BSD environments too. Someone could write an implementation
of poll() that uses select(), for these environments, but I've never
seen one. Both select() and poll() are being standardized by POSIX
1003.1g.
Does that answer your question well enough?
I searched the same thing a while back, when trying to figure out which one to use in my multisocket program, and have to admit that knowing almost nothing about those at first it proved a little difficult to make the choice back then
@b0uncer , i had already gone through the same what you post, what is the main purpose that select came into picture , and how the poll is distinguish from that..???
Like it says there (and apparently a bunch of other places as well), both can be used for the same tasks, so it's up to the programmer to choose one. I think I read somewhere that poll() can notify you about more events than select() can, so it could have "broader usability"; though that's a limited benefit, as it probably depends on the implementation (what you need). Some programs even use both; if there's poll() available, the program may make use of it, and if there isn't, do the job with select() instead. And there are probably other means as well that can achieve the same results that poll() and select() can, those two just happen to be the "standardized" ways I think.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.