#!/usr/bin/perl use strict; use warnings; use IPC::Open3; # uncomment to handle SIGPIPE yourself # $SIG{PIPE} = sub { warn "Broken pipe\n" }; open3(my $wh, my $rh, undef, qw'echo foo'); # tiny delay, so the command _has_ closed its stdin in the meantime select undef,undef,undef, 0.2; print $wh "foo\n"; # expected to fail in this case close $wh; print "done.\n"; # not reached, except when handling SIGPIPE yourself #### $ strace ./747486.pl (...) select(0, NULL, NULL, NULL, {0, 200000}) = ? ERESTARTNOHAND (To be restarted) --- SIGCHLD (Child exited) @ 0 (0) --- select(0, NULL, NULL, NULL, {0, 200000}) = 0 (Timeout) write(8, "foo\n", 4) = -1 EPIPE (Broken pipe) --- SIGPIPE (Broken pipe) @ 0 (0) --- +++ killed by SIGPIPE +++