[Chicago-talk] Broken Pipe

Young, Darren Darren.Young at ChicagoGSB.edu
Mon Dec 12 13:27:52 PST 2005


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 |
-------------------------------------------------------------


More information about the Chicago-talk mailing list