Marcello has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

Can pipes time out? I have long-running processes which communicate with a parent process using a pipe. If the process does not write to the pipe for approx. 12 hours, the next write triggers a SIG{'PIPE'} signal. The pipe is still intact, because other writes to the pipe after this SIG{'PIPE'} do not trigger the signal anymore. It only appears once after a long period of no writes to the pipe.

I am creating the pipe using socketpair followed by a fork:
socketpair($child, $parent, AF_UNIX, SOCK_STREAM, PF_UNSPEC);
I can simply 'IGNORE' the signal, but still I am curious why this is happening and if I can prevent it. The platform is Linux.

Thanks!

Replies are listed 'Best First'.
Re: SIG{'PIPE'} and pipe timeout
by zentara (Cardinal) on Feb 06, 2006 at 13:40 UTC
    It looks like you are creating sockets, not pipes. It sounds like you may have some other pipe involved, which may be hidden from you.

    I'm not really a human, but I play one on earth. flash japh
      Thank you for your reply.

      socketpair is mentioned in Perl IPC as one of the methods to create two pipes. There are no other pipes created, and it happens as soon as the process is writing to the pipe.

      Regards, Marcel
        I don't want to start arguing over this, but I read that section in perlipc, and it dosn't say that pipes are created with socketpair. It says that socketpair is preferred for bidirectional communication , over 2 pipe pairs. The name, "pipe2" may be misleading.
        ....snip...... # pipe1 - bidirectional communication using two pipe pairs # designed for the socketpair-challenged ...snip....... But you don't actually have to make two pipe calls. If you have the +socketpair() system call, it will do this all for you. #!/usr/bin/perl -w # pipe2 - bidirectional communication using socketpair # "the best ones always go both ways"

        So you are not creating a pipe with socketpair, that is why I brought it up in my original post, about you relating a SIG{PIPE} to the socketpair. I was thinking that somewhere in your program, you had a pipe ( liked a piped open ) which prints to the socket.

        It really would be good if you could show a snippet of code which gives your error. Does the code in perlipc (pipe2), showing how to use a socketpair, work OK for you? It works OK for me. How does your code differ from it?


        I'm not really a human, but I play one on earth. flash japh