I am starting a process, and redirecting its output to a named pipe. I’m reattaching to the named pipe with with cat > $pipe. How do I set the named pipe to die when the process’ stdout dies without polling for the parent process’ death?
Aside from that, what else besides cat can be used to open named pipes?
a fifo is always ready to read and write, so a program like
catandtail -fwill not stop reading, ever. What you want to check is whether there’s a process that writes to that file, and if there is no such process, stop reading. (btw, the best way to read a file, is toreadit.)lsofcan tell you who reads and writes from/to a specified file. Look in its man page, and try something like:I am not sure, and do not have the time to look into lsof, to find out which option outputs only processes that write to that file. Please look into that on the man page.
So, as long as there is a process that writes to the fifo, this scripts read a line and prints it. Once there is no process writting to the file, the loop breaks and the script exits.
I do not know of another way to check whether there is a process writing to a file other than using
lsof. If anyone does know a more standard way, I would like to know too.