[ale] Named Pipe

Brian Pitts bpitts at learnlink.emory.edu
Tue Mar 20 17:08:18 EDT 2007


Atlanta Linux Enthusiasts wrote:
> I have an application for which a named pipe seems like the right 
> answer on
> several fronts, but what I don't want is for the writing application 
> to block
> if there is noone reading it.  I just want one application to stream 
> data to
> the pipe, and have some other application be able to jump in 
> 'mid-stream' and
> start processing the input data.
>
> Is this possible with linux named pipes?
I don't believe any Unix has a way of storing data in named pipes 
permanently. Even if the O_NONBLOCK flag is set, an open for write on a 
named pipe with no reader should return -1. However, you can get around 
this by having the process doing the writing open it for reading first 
(also nonblocking of course). While there isn't a reader, your writer 
will eventually fill the pipe buffer. You'll need to check the return 
value of write to determine when this happens, and then read PIPE_BUF  
amount of data to clear it.

If any of this is wrong, send complaints to km at mathcs.emory.edu ;-)

I'm assuming that when you say you want an application to be able to 
jump in "mid-stream", this mean you're okay with discarding data.

-Brian



More information about the Ale mailing list