Disabling buffering in a read pipe

Disabling buffering in a read pipe

Post by Henry Cooks » Thu, 02 Mar 1995 03:45:55



I'm having trouble disabling buffering input from a read pipe.  I'm using
popen() to create the pipe, and fgets to read the pipe.  I'm getting the
input in large chunks, and none 'til the buffer fills.  I'd like to get the
output as it is being produced, but all attempts to use ioctl(), fcntl()
and nbuf() were unsuccessful.  

One guess I have is that I have to use pipe() so that I can alter these
settings from the child process before execing the command.  I was
hoping to disable buffering by using the file pointer returned by popen().

--Henry Cookson
--Computer Sciences Corp.

 
 
 

Disabling buffering in a read pipe

Post by Harold Finkbein » Sat, 04 Mar 1995 09:31:22




> I'm having trouble disabling buffering input from a read pipe.  I'm using
> popen() to create the pipe, and fgets to read the pipe.  I'm getting the
> input in large chunks, and none 'til the buffer fills.  I'd like to get the
> output as it is being produced, but all attempts to use ioctl(), fcntl()
> and nbuf() were unsuccessful.  

> One guess I have is that I have to use pipe() so that I can alter these
> settings from the child process before execing the command.  I was
> hoping to disable buffering by using the file pointer returned by popen().

You should be able to use setvbuf() with a type of _IONBF (at least on
our system).  This must be done before any reads or writes to the pipe.

-Harold

 _____                                                          _____
( ___ )--------------------------------------------------------( ___ )

 | / | Stanford University  Phone: (415) 725-3353               | \ |
 | / |                                                          | \ |
 |___|            #include <standard.disclaimer.h>              |___|
(_____)--------------------------------------------------------(_____)

 
 
 

Disabling buffering in a read pipe

Post by Stephen Reppuc » Wed, 08 Mar 1995 23:43:04




>I'm having trouble disabling buffering input from a read pipe.  I'm using
>popen() to create the pipe, and fgets to read the pipe.  I'm getting the
>input in large chunks, and none 'til the buffer fills.  I'd like to get the
>output as it is being produced, but all attempts to use ioctl(), fcntl()
>and nbuf() were unsuccessful.  

>One guess I have is that I have to use pipe() so that I can alter these
>settings from the child process before execing the command.  I was
>hoping to disable buffering by using the file pointer returned by popen().

>--Henry Cookson
>--Computer Sciences Corp.


Are you certain that it's the input to your process that's being buffered,
and not the output from the process you're invoking at the other end
of your pipe?  I believe that you need to make certain that the writer
is not buffering its output (assuming you have control over it.)

<Steve Reppucci, Fax International>

 
 
 

1. pipe read buffer flush

Problem:  Getting data FROM a pipe without waiting for a buffer flush to be
          performed on the writing end.

When I write code that looks like this:

fp = popen ( "sar -u 5 99999", "r" );
while ( 1 )
   {
   if ( fgets (pipe_result, sizeof(pipe_result)-1, fp) == NULL )
      {
      pclose (fp);
      break;
      }
/*  Do something interesting with pipe_result  */
   }

I do indeed get the expected results from the pipe (i.e. appropriate sar
output), BUT it does not give me each line from sar as it is being generated.
Instead, I get a bunch of lines every 30 seconds or so.

Apparently the output buffer (for sar) is being filled and flushed at that
interval.

What I really want is to get each line as it is written by sar;  i.e. force a
buffer flush after each line (apparently).

Any ideas?

Thanks in advance.

2. detecting 64bit mode in Solaris 7

3. pipe/buffer-command for buffering large amounts of I/O

4. how to install from kickstart

5. Help needed with configuring TCP/IP under Linux.

6. Parse a buffer : Make lex read a buffer rather than a file ?

7. Branching down to subdirs using grep

8. A simple link,write buffer is full and read buffer is empty.

9. assert (1 != read(fd,Buffer, sizeof(Buffer)-1));

10. read() reads less chars than buffer allows!

11. read() does not return bytes read from FIFO - pipe.txt [1/1]