[Nottingham] named pipes (fifo) help please

Martin Garton martin at stupids.org
Wed Oct 26 16:21:18 BST 2005


On Wed, 2005-10-26 at 16:09 +0100, Martin wrote:
> Folks,
> 
> I want to use a named pipe to let a second process read at random times 
> the "latest results" from a first process...
> 
> What's the best/easiest way to avoid the first (writing) process 
> blocking on the pipe if the second process doesn't read for a long time?
> 
> What I'm really after is just for the latest line of output to be picked 
> up by the second process without risking a partial read if I use a text 
> file for example instead of the pipe...

For that, I wouldn't use a pipe but just a standard file.  You can avoid
the partial read by writing to "foo" from process 1 before doing "mv foo
bar" (overwriting any previous bar) and just read from bar in process 2.

If on the same filesystem, mv uses rename(2) which is atomic for file
replacement. (because you are not actually moving any data. the inode is
not changed, just the link)


-- 
M.





More information about the Nottingham mailing list