What is the difference between close() and shutdown()?



What is the difference between close() and shutdown()?..

Answer / chaitanya

Generally the difference between close() and shutdown() is: close() closes the socket id for the process but the connection is still opened if another process shares this socket id. The connection stays opened both for read and write, and sometimes this is very important. shutdown() breaks the connection for all processes sharing the socket id. Those who try to read will detect EOF, and those who try to write will reseive SIGPIPE, possibly delayed while the kernel socket buffer will be filled. Additionally, shutdown() has a second argument which denotes how to close the connection: 0 means to disable further reading, 1 to disable writing and 2 disables both.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Unix Socket Programming Interview Questions

Why do we need sockets?

0 Answers  


How come only the first part of my datagram is getting through?

1 Answers  


If bind() fails, what should I do with the socket descriptor?

1 Answers  


How do I get the port number for a given service?

1 Answers  


How many sockets can a port have?

0 Answers  






over the socket? Is there a way to have a dynamic buffer? What does one do when one does not know how much information is coming?

1 Answers  


What are raw sockets?

4 Answers   Axis Technologies,


Can a single socket port be used for multiple applications?

0 Answers  


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

0 Answers  


What is the difference between SO_REUSEADDR and SO_REUSEPORT?

0 Answers  


How to find other end of unix socket connection?

0 Answers  


Why does the sockets buffer fill up sooner than expected?

0 Answers  


Categories