[Chicago] capturing output from subprocesses

Martin Maney maney at two14.net
Tue Nov 8 21:17:05 CET 2005


On Tue, Nov 08, 2005 at 12:40:04PM -0600, Ian Bicking wrote:
> Noel Thomas Taylor wrote:
> > Do you have any thoughts about recapturing the output of an aborted child 
> > process before the memory that is buffering its output gets blown away?
> 
> Since it is OS buffering, shouldn't the OS handle that for you?  I don't 
> know; I would suggest starting with a test, then finding something that 
> passes that test.

Ah, but that's just it - it's NOT the OS that's doing the bufferring. 
C's standard IO library uses bufferred IO for efficency - it's much
faster than doing a system call for every character.  Back in the old
days the buffer was often only 512 bytes, but I'm sure that modern
library implementations will allocate a larger buffer by default.

No, I'm very much afraid that the problem is that the apps are
internally buffering the output, and that buffer isn't flushed by an
abnormal termination (which is actually a feature, I'm afraid).  I have
since thought that you might be able to change this normal bufferring
in the C library by playing games with LD_PRELOAD and a modified (and
subsetted, I should think) library, but that's probably no more
portable, and a good deal more work, than PTYs.

If you're willing to use solutions that aren't portable, I have a vague
notion that the GNU libc, at least, might provide a hack to control
this buffering through the environment.  Though I can't find anything
about it now, so maybe that was some other implementation...

-- 
If software vendors have liability costs, they'll pass those
on to us.  It might not be cheaper than what we're paying today,
but as long as we're going to pay, we might as well
pay to fix the problem.  -- Bruce Schneier



More information about the Chicago mailing list