[Chicago-talk] Broken Pipe

Jess Balint jbalint at gmail.com
Mon Dec 12 13:47:54 PST 2005


Although it is remotely possible, I have never heard of an implicit timeout
on reading (whether from a pipe or anything else). Can you verify that the
child process is not exiting abnormally? Can you provide some more detail on
the commands you are running and the type of output you are expecting?

Open3 would be necessary if you want to capture the out and err streams
separately. This might help if your child process is printing error messages
that you are unaware of.

One thing to try might be using the read() system call instead of the
line-oriented input. It is just a way to guarantee that all the data is
read.

Jess

-----Original Message-----
From: chicago-talk-bounces at pm.org [mailto:chicago-talk-bounces at pm.org] On
Behalf Of Young, Darren
Sent: Monday, December 12, 2005 4:28 PM
To: chicago-talk at pm.org
Subject: [Chicago-talk] Broken Pipe

Have a script that does an open() for read on a pipe. The particular
binary can take a while to run (1-2 hours) and causes the Perl open() to
eventually timeout and spew back 'broken pipe'. Can I do something as
simple as:

$SIG{PIPE} = 'IGNORE';

To get around this? Or, should I be thinking about a different IPC open
mechanism (open2, open3, etc)?

The actual code that does the open() is:

sub store_cleanup {

    my $cmd;
    my $start;
    my $end;
    my $runtime;

    if ( $VERBOSE ) {
        $cmd = "$stored -1 -v 2>&1";
    } else {
        $cmd = "$stored -1";
    }

    debug("cmd: $cmd");

    # open it up as a pipe
    logmsg("Opening stored command pipe");
    if ( open(STORED, "$cmd |") ) {
        $start = time();
        logmsg("Pipe opened at " . localtime($start));
        while(<STORED>) {
            chomp();
            logmsg($_);
        }
        my $end = time();
        close(STORED);

        $runtime = $end - $start;
        $runtime_min = sprintf("%.1f", $runtime / 60);
        logmsg("  Start time : " . localtime($start));
        logmsg("    End time : " . localtime($end));
        logmsg("    Run time : $runtime seconds ( $runtime_min minutes
)");
        return(0);
    } else {
        logmsg("Failed to open stored as a pipe ($!)");
        return(0);
    }                                                     
    return(1);

}

Anyone have any thoughts?

-------------------------------------------------------------
| Darren Young              | http://www.chicagogsb.edu     |
| Senior UNIX Administrator | darren.young at chicagogsb.edu   |
| University of Chicago GSB | darren.young at gsb.uchicago.edu |
-------------------------------------------------------------
_______________________________________________
Chicago-talk mailing list
Chicago-talk at pm.org
http://mail.pm.org/mailman/listinfo/chicago-talk



More information about the Chicago-talk mailing list