4

I'm trying to connect two machines, say machine A and B. I'm trying to send TCP message from A to B (One way). In normal scenario this works fine. When the communication is smooth, if the socket in B is closed, send() from A is stuck forever. And it puts process into Zombie state. I have socket in blocked mode in machine A. Below is the code that stuck forever.

           if (send (txSock,&txSockbuf,sizeof(sockstruct),0) == -1) {
                printf ("Error in sending the socket Data\n");
                            }
            else {
                printf ("The SENT String is %s \n",sock_buf);
            }

How do I find if the other side socket is closed?? What does send return if the destination socket is closed?? Would select be helpful.

André Puel
  • 8,741
  • 9
  • 52
  • 83
Kitcha
  • 1,641
  • 6
  • 19
  • 20

1 Answers1

7

A process in the "zombie" state means that it has already exited, but its parent has not yet read its return code. What's probably happening is that your process is receiving a SIGPIPE signal (this is what you'll get by default when you write to a closed socket), your program has already terminated, but the zombie state hasn't yet been resolved.

This related question gives more information about SIGPIPE and how to handle it: SIGPIPE, Broken pipe

Community
  • 1
  • 1
Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285
  • Thank you. Let me look into that. – Kitcha Jul 27 '11 at 00:08
  • Understood. Is there a way to find out whether the pipe is broken even before I try my write/send? – Kitcha Jul 27 '11 at 00:22
  • 1
    No. Because the pipe might become broken at any time, even if there were a way to check before writing, it could become broken *after* you checked and *before* you called `send()`. The only way to check is to try. – Greg Hewgill Jul 27 '11 at 00:41