2

I'm having trouble with buffers :

I have a daemon D, and its monitor M. D is started before M, and M prints any relevant information to the tty, and I need to parse this information and give it to a program of my own.

Since I want to automate this, M should print to a file. But it doesn't until the daemon has been killed, because of buffers.

So I was thinking of recording the tty and therefore tried to use script to record the output to the terminal but ... it's buffered also ...

I also tried getting access to the gnu coreutils (to make use of stdbuf which I apparently need) but had to give up when I couldn't install the utility to unzip the peculiar .xz format proposed on GNU's website !

I fear I'm not even doing the right thing ! Isn't there a simple solution to this problem that potentially everyone who works with real-time has had ??

A little help would be much appreciated. Thanks.

gqq
  • 21
  • 1

1 Answers1

1
  1. the .xz file format can be extracted with xz or 7zip
  2. there appears to be a LD_PRELOAD hack to achieve the same result too: http://lists.gnu.org/archive/html/bug-coreutils/2008-11/msg00164.html

This page is my preferred reference on stdio buffering: http://www.pixelbeat.org/programming/stdio_buffering/

PS. 'everyone who works with real-time' presumably uses IPC and doesn't rely on bash. Perl, python and obviously all lower-level languages provide ways to explicitely disable/enable buffering

sehe
  • 374,641
  • 47
  • 450
  • 633
  • Hi sehe, It's actually not the .xz that gave me headaches, rather the utility to unzip it (xz...) that failed to install on my machine. But I went back to the repository and found a nicely packaged .tar.gz. I have already seen both links (or equivalents) that you provided me with but failed to understand how to apply it to my problem. I will re-read them both though. – gqq Jun 01 '11 at 13:40
  • 1
    Okay, so I managed to install stdbuf and it's exactly what I needed ! I used stdbuf -oL as a prefix for my daemon and its monitor. I think I still miss part of the actual recording (1 line) but it's no important information so I'll consider that done for the time being. Thank you for your guidance, re-reading the pixelbeat page I finally understood why libc was involved, and the stdbuf trick works very nicely ;) Edit : the stdbuf is based on the LD_PRELOAD hack you mentioned. – gqq Jun 01 '11 at 14:12