bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

preventing pipe reader from existing on writer exiting


From: Brian J. Murrell
Subject: preventing pipe reader from existing on writer exiting
Date: Wed, 30 Sep 2009 15:14:53 -0400

Let's say I have the following (contrived, simplified example):

$ mknod /tmp/fifo
$ cat /dev/zero > /tmp/fifo &
$ cat < /tmp/fifo

When the first cat exits (i.e. is terminated) the second cat stops.  The
problem is that I want to be able to restart the first cat and have the
second cat just keep reading such as:

$ mknod /tmp/fifo
$ (n=; while [ $n -lt 10 ]; do cat /dev/zero > /tmp/fifo; let n=$n+1; done) &
$ pid=$!
$ cat < /tmp/fifo
$ kill $pid

Where $n is a safety valve against an endless loop of cat just exiting
over and over again.

But of course that doesn't work because the second cat exits when the
first iteration of the first subshell exits.  Additionally, the kill
only kills the subshell and not any of it's children.  So to solve the
second cat exiting issue I considered:

$ mknod /tmp/fifo
$ (n=; while [ $n -lt 10 ]; do cat /dev/zero > /tmp/fifo; let n=$n+1; done) &
$ pid=$!
$ (n=; while [ $n -lt 10 ]; do cat < /tmp/fifo; let n=$n+1; done)
$ kill $pid

This has the desired effect except for the issue of not being able to
kill $pid's children.

So now I figure I must just be going about this all the wrong way.

Can anyone help?  Ultimately I need to do I/O through a named pipe and I
need to be able to restart the writer without restarting the reader.

Cheers,
b.



Attachment: signature.asc
Description: This is a digitally signed message part


reply via email to

[Prev in Thread] Current Thread [Next in Thread]