Non-blocking buffered named pipe

io-redirectionpipe

I'm looking for something I suspect doesn't exist: A non-blocking buffered named pipe (fifo) for use from the command line. Is there such a thing?

Here's the use case: Suppose I have a process that's going to run a long time in the background and spew a lot of output to stdout. I don't really care about the output and don't want to store it (perhaps I don't have enough room to), but I'd like to "drop in" periodically and follow what it's doing, then drop out again and leave it to do its work. So I'd like to redirect its output to this theoretical buffered, non-blocking named pipe and then periodically tap into it.

So basically I want to start like this (10M being the size of the buffer):

mkmagicfifo magicfifo 10M
spewingprocess > magicfifo &

…and periodically drop in to see what's going on…

tail -f magicfifo

without magicfifo storing all the output (so, not a normal file), and without it blocking the spewing process when it fills up and isn't tapped (so, not quite a normal named pipe).

I don't think solutions involving tail or prune will do it (well, I can think of a workaround involving tail), because tail would still require that I store all the data somewhere (if I want to drop in and drop out of looking at it), and prune has to rewrite the file, presumably (I'll admit I haven't tried/proven this) breaking the redirection of the process generating all the output.

I expect I could write some utility to do this, but *nix has so many cool aspects of files and pipes and such, I just can't help but think this exists and I just don't know about it.

So: Is there such a thing, and if so what is it?

Best Answer

I think what you are looking for is GNU screen. It maintains a buffer to hold the last screen full or two of output from one or more programs and lets you disconnect and come back later.