LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 08-30-2008, 11:57 AM   #1
dina3e
Member
 
Registered: Mar 2008
Location: Bangalore
Distribution: Enterprise Red Hat linux
Posts: 98

Rep: Reputation: 16
Differance Between Select ( ) and Poll ( )


i am gone through the several web but not getting the satisfactory difference between these two system call.
 
Old 08-31-2008, 05:01 AM   #2
pinniped
Senior Member
 
Registered: May 2008
Location: planet earth
Distribution: Debian
Posts: 1,732

Rep: Reputation: 50
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.
 
Old 08-31-2008, 05:02 AM   #3
b0uncer
LQ Guru
 
Registered: Aug 2003
Distribution: CentOS, OS X
Posts: 5,131

Rep: Reputation: Disabled
Quoted from unixguide.net page:

Quote:
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
 
Old 09-02-2008, 08:18 AM   #4
dina3e
Member
 
Registered: Mar 2008
Location: Bangalore
Distribution: Enterprise Red Hat linux
Posts: 98

Original Poster
Rep: Reputation: 16
@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..???
 
Old 09-02-2008, 08:23 AM   #5
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,671
Blog Entries: 4

Rep: Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945
Essentially, one is the intended successor to the other.

Having said that, "obviously, both will continue to co-exist forever."
 
Old 09-02-2008, 08:34 AM   #6
b0uncer
LQ Guru
 
Registered: Aug 2003
Distribution: CentOS, OS X
Posts: 5,131

Rep: Reputation: Disabled
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.
 
  


Reply

Tags
poll, select



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Emulator for POLL SELECT Jose Rivas Fedora 2 01-22-2007 08:01 AM
how is select()/poll() effected by clock setting? d71 Linux - Kernel 3 12-02-2006 03:00 PM
poll/select in tty driver metso777 Linux - Kernel 0 11-13-2006 09:57 AM
select/poll and Signal Safety nopcoder Programming 9 01-30-2006 07:05 PM
what is the differance juanb Linux - General 2 01-10-2003 05:16 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 05:17 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration