Unix Socket Programming Question:
Download Questions PDF

What are the pros/cons of select(), non-blocking I/O and SIGIO?

Answer:

Using non-blocking I/O means that you have to poll sockets to see if there is data to be read from them. Polling should usually be avoided since it uses more CPU time than other techniques.

Using SIGIO allows your application to do what it does and have the operating system tell it (with a signal) that there is data waiting for it on a socket. The only drawback to this soltion is that it can be confusing, and if you are dealing with multiple sockets you will have to do a select() anyway to find out which one(s) is ready to be read.

Using select() is great if your application has to accept data from more than one socket at a time since it will block until any one of a number of sockets is ready with data. One other advantage to select() is that you can set a time-out value after which control will be returned to you whether any of the sockets have data for you or not.

Download Unix Socket Programming Interview Questions And Answers PDF

Previous QuestionNext Question
How can I force a socket to send the data in its buffer?Why does it take so long to detect that the peer died?