Reputation: 3111
I wonder what happens if stdout buffer will be overflowed?
For example: app 1
launches the app 2
, writes N
lines to its stdin
and THEN reads its stdout
. Second app is just rewrites all it's got from stdin
to stdout
. At the moment app 1
finishes writing of N
lines to app 2
and switches to reading its stdout
the app 2
has already finished printing out lines to stdout
. And this data is in its stdout's buffer. With increase of N
we can overflow buffer.
What happens then? Will app 2
crash or its process blocks? If it's a crash what will be error code (linux)?
EDIT: Some code http://pastebin.com/msMRdxGR
I'm getting SIGPIPE error. (and used wrong labels - app1 is app2 and vice versa).
Sorry for not asking from beginning, but is there a way to avoid this error? If app2 uses 2 threads - one for reading and other for writing. And internal dynamically allocated buffer in heap to exchange data between them. Then I could just suspend writing thread from reading thread if noone reads my stdout. But how can I detect that stdout buf will be soon overflowed?
Upvotes: 3
Views: 1674