Difference: Your large program uses $SIG{ PIPE } = "IGNORE";.
Solution: Add local $SIG{ PIPE } = "DEFAULT"; in scope of your open. Alternatively, you could redirect zcat's STDERR to /dev/null.
Take a look at this:
seq 1000000000 | gzip | zcat | head
It should take a long time to generate and unzip that stream, but it doesn't.
$ time ( seq 1000000000 | gzip | zcat | head )
1
2
3
4
5
6
7
8
9
10
real 0m0.051s
user 0m0.056s
sys 0m0.005s
This is what happens:
- Once head has printed its ten lines, it exits.
- This breaks the pipe from zcat to head.
- The next time zcat attempts to write to the pipe, SIGPIPE is sent to it.
- Upon receiving SIGPIPE, zcat is killed.
- gzip is similarly killed by SIGPIPE.
- seq is similarly killed by SIGPIPE.
The above is what happens in your standalone script.
In your larger program, you appear to have used $SIG{ PIPE } = "IGNORE";. It's still just as quick, but the error message now appears.
$ seq 1000000000 | gzip | perl -e'$SIG{ PIPE } = "IGNORE"; exec("zcat"
+)' | head
1
2
3
4
5
6
7
8
9
10
gzip: stdout: Broken pipe
This is what happens now:
- zcat inherits its parent's disposition of ignoring SIGPIPE.
- Once head has printed its ten lines, it exits.
- This breaks the pipe from zcat to head.
- The next time zcat attempts to write to the pipe, SIGPIPE is sent to it.
- zcat ignores the SIGPIPE.
- The write call returns error EPIPE.
- zcat exits with a message as a result of the error. (zcat is an alias for gzip, which is why the message says gzip.)
- gzip is killed by SIGPIPE.
- seq is killed by SIGPIPE.
Add local $SIG{ PIPE } = "DEFAULT"; in scope of your open.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.