In socket programming in Linux I need to write data in socket but I don\'t know socket is open or close . how to I know that socket is open and close without read ?
Socket programming can be rather tricky, because you often don't know an error has occurred until much later.
For instance, if the machine you are writing to shuts down abnormally, the write call may succeed ( because you were able to write to your internal OS buffers ), only to fail during the close call.
Unless you have an application-layer way of verifying the socket is active ( i.e., sending a message and requiring a response within some time period ) you have no way of knowing. If you are using a standard protocol, something may already exist to handle errors.
So the short answer is that you need to check for error returns from pretty much every call that touches the socket ( read, write, close, etc... ).